function verifica_formulario()
{

	var mensagem_erro='';
	if(!get_vlr_campo_str('titulo') )
	{
		mensagem_erro+='\nO álbum é um campo obrigatório.';
	}
	if(!get_vlr_campo_str('autor') )
	{
		mensagem_erro+='\nO artista é um campo obrigatório.';
	}
	if(!get_vlr_campo_str('info') )
	{
		mensagem_erro+='\nInfo é um campo obrigatório.';
	}
	if(get_vlr_campo('preco')=="" || get_valor_campo(document.getElementById('preco'), '___rea')<1)
	{
		mensagem_erro+='\nO preço é um campo obrigatório.';
	}
	
	
	
	if(mensagem_erro=="" )
	{				
		//alert("submit");
		document.getElementById("flg_salvar").value=1;	
		document.forms["form_cadastro"].submit();
	}
	else	
	{	
		alert(mensagem_erro);
		
	}
	
}
function get_valor_campo(elemento, tipo_campo)
	{
		var id_campo = "";
		if (elemento.id)
		{
			id_campo = elemento.id;
		}
		else
		{
			id_campo = elemento;
		}
		var valor = "";
		

		switch (tipo_campo)
		{
			case "___c2c"://dois combos
				valor = document.getElementById(id_campo).value;
			break;
			case "___ckb"://checkbox
/*				if (document.getElementById(id_campo+"_0")) //checkbox
				{
					var contador = 0;
					var checado = false;
					try
					{
						while( document.getElementById(id_campo+"_"+contador) )
						{
							if (document.getElementById(id_campo+"_"+contador).checked)
							{
								valor += document.getElementById(id_campo+"_"+contador).value+",";
							}
							contador++;
						}
						valor = valor.substr(0, (strlen(valor)-1) );
					}
					catch(e) {}
				}*/
				valor = document.getElementById(id_campo).value;
			break;
			case "___rad":
				if (document.getElementById(id_campo+"_0")) //radio
				{
					var contador = 0;
					var checado = false;
					try
					{
						while( document.getElementById(id_campo+"_"+contador) )
						{
							if (document.getElementById(id_campo+"_"+contador).checked)
							{
								valor = document.getElementById(id_campo+"_"+contador).value;
							}
							contador++;
						}
					}
					catch(e) {}
				}
			break;
	
			case "___dta"://data
			case "___dth"://data e hora
			case "___dsm"://data select mes
			case "___hms"://hora e minuto segundo
			case "___hmi"://hora e minuto
				if (id_campo.substr(0,4) == "dia_" || id_campo.substr(0,4) == "mes_" || id_campo.substr(0,4) == "ano_" ||
					id_campo.substr(0,4) == "hor_" || id_campo.substr(0,4) == "min_" || id_campo.substr(0,4) == "seg_")
				{
					if (document.getElementById(id_campo))
					{
						id_campo = id_campo.substr(4)
					}
				}
				var input1 = document.getElementById("dia_"+id_campo);
				var input2 = document.getElementById("mes_"+id_campo);
				var input3 = document.getElementById("ano_"+id_campo);

				if (input3 && input2 && input1)
				{
					valor = input3.value+"-"+input2.value+"-"+input1.value
				}
				if (tipo_campo != "___dta" && document.getElementById("hor_"+id_campo))
				{
					if (input3 && input2 && input1)
					{
						valor += " ";
					}
					valor += document.getElementById("hor_"+id_campo).value;
					valor += ":"+document.getElementById("min_"+id_campo).value;
				}
				if (tipo_campo == "___hms" && document.getElementById("seg_"+id_campo))
				{
					valor += ":"+document.getElementById("seg_"+id_campo).value;
				}
			break;
	
			case "___edt"://editor
				var insere_texto_editor = FCKeditorAPI.GetInstance(id_campo);
			    valor = insere_texto_editor.GetXHTML();
			break;

			case "___dat"://data input
				var temp = document.getElementById(id_campo).value;
				var itens_hora = temp.split(" ");
				var data = itens_hora[0];
				var itens_data = data.split("/");
				
				valor = itens_data[2]+"-"+itens_data[1]+"-"+itens_data[0];
			break;
			case "___dhi"://data hora input
				var temp = document.getElementById(id_campo).value;
				var itens_hora = temp.split(" ");
				var data = itens_hora[0];
				var hora = itens_hora[itens_hora.length-1];
				var itens_data = data.split("/");
				
				valor = itens_data[2]+"-"+itens_data[1]+"-"+itens_data[0]+" "+hora;
			break;

			case "___rea"://real
				valor = unformat_real(document.getElementById(id_campo).value);
			break;

			case "___psw"://senha
			case "___cor"://cor
			case "___txt"://texto
			case "___str"://caracter
			case "___int"://inteiro
			case "___vet"://tabela interna
			default:
				if (document.getElementById(id_campo))
				{
					valor = document.getElementById(id_campo).value;
				}
			break;
		}
		return valor;
	}
	function unformat_real(num) 
	{
		num = num.replace(/\$|\./g,'');
		num = num.replace(/\$|\,/g,'.');
		return num*1.0;
	}
function get_vlr_campo_str(nome)
{	
	if(document.getElementById(nome))
	{
		return document.getElementById(nome).value;
	}
}
function get_vlr_campo(nome)
{
	
	if(document.getElementById(nome))
	{
		return document.getElementById(nome).value*1;
	}
}
function SetarMascara(elemento, Tipo, Mascara)
	{
		// Filtra navegadores conhecidos
		var s = QualNavegador();
		if (s.length == 0 || ((s == "IE") && (QualVersao() < 6)) || ((s == "NE") && (QualVersao() < 5)))
		{
			return;
		}
		if (elemento.onkeypress == null)
		{
			elemento.tipo = Tipo;
			elemento.mascaracustom = Mascara;
			elemento.onkeypress = VerificaTecla;
		}
		
/*		if (elemento.onkeyup == null)
		{
			elemento.tipo = Tipo;
			elemento.onkeypress = VerificaDigitado;
		}*/

//		elemento.className = "input-sel";
		
//		alert(elemento.onfocus);
	}
	
	function VerificarMascara(elemento, tipo)
	{
		if (elemento.value && elemento.type != "select" && elemento.type != "select-multiple")
		{
			var valor = elemento.value;
			var result = "";

			for (var i = 0; i < valor.length; i++)
			{
				if (TeclaPermitida(valor.charCodeAt(i), elemento, false, i))
				{
					result += valor.charAt(i);
				}
			}

			elemento.value = result;
		}
	}
	
	function VerificaTecla(evnt)
	{
		var tecla;
		var ret = true;
	
		tecla = ( (QualNavegador()=="IE") ? event.keyCode : evnt.which);
		if (tecla < 32)
			return true;
	
		return TeclaPermitida(tecla, this, true);
	}
	
	function TeclaPermitida(tecla, elemento, digitando, posicao)
	{
		var tipo = elemento.tipo;
		var ret = true;
		switch (tipo)
		{
			case "___tel"://telefone
				ret = (tecla >= 48 && tecla <= 57 );
				if (digitando)
				{
					ret = formatar_valor_mascara(tecla,elemento,"(##)####-####");
				}
				else
				{
					ret = ret || (String.fromCharCode(tecla) == '(' || String.fromCharCode(tecla) == ')' || String.fromCharCode(tecla) == '-');
				}
			break;
			case "___cpf"://cpf
				ret = (tecla >= 48 && tecla <= 57 );
				if (digitando)
				{
					ret = formatar_valor_mascara(tecla,elemento,"###.###.###-##");
				}
				else
				{
					ret = ret || (String.fromCharCode(tecla) == '.' || String.fromCharCode(tecla) == '-');
				}
			break;
	
			case "___cep"://CEP
			case "___cpc"://CEP Correios
				ret = (tecla >= 48 && tecla <= 57 );
				if (digitando)
				{
					ret = formatar_valor_mascara(tecla,elemento,"##.###-###");
				}
				else
				{
					ret = ret || (String.fromCharCode(tecla) == '.' || String.fromCharCode(tecla) == '-');
				}
			break;

			case "___cnj"://CNPJ
				ret = (tecla >= 48 && tecla <= 57 );
				if (digitando)
				{
					ret = formatar_valor_mascara(tecla,elemento,"##.###.###/####-##");
				}
				else
				{
					ret = ret || (String.fromCharCode(tecla) == '.' || String.fromCharCode(tecla) == '/' || String.fromCharCode(tecla) == '-');
				}
			break;
			
			case "___msk"://Máscara customizada
				//ret = (tecla >= 48 && tecla <= 57 );
				if (digitando)
				{	
					mascara = elemento.mascaracustom;
					ret = formatar_valor_mascara(tecla,elemento,mascara);
				}
				else
				{
					ret = ret || (String.fromCharCode(tecla) == '.' || String.fromCharCode(tecla) == '-');
				}
			break;
	
			case "___hms"://hora minuto segundo
			case "___dth"://data hora
			case "___hmi"://hora minuto
			case "___dta"://data
				ret = (tecla >= 48 && tecla <= 57 );
			break;
			
			case "___dat":
				ret = (tecla >= 48 && tecla <= 57 );
				if (digitando)
				{
					ret = formatar_valor_mascara(tecla,elemento,"##/##/####");
				}
				else
				{
					ret = ret || String.fromCharCode(tecla) == '/'; 
				}
			break;
			case "___dhi":
				ret = (tecla >= 48 && tecla <= 57 );
				if (digitando)
				{
					ret = formatar_valor_mascara(tecla,elemento,"##/##/#### ##:##");
				}
				else
				{
					ret = ret || (String.fromCharCode(tecla) == '/' || String.fromCharCode(tecla) == ' ' || String.fromCharCode(tecla) == ':'); 
				}
			break;
	
			case "___inm":
				ret = (tecla >= 48 && tecla <= 57 ) || (tecla == 45) || (tecla == 46);//Digito , - .
			break;

			case "___inp":
				if (tecla == 45)
				{
					ret = false;
					break;
				}
			case "___num":
			case "___int": // Digitos e menos(-)
				ret = (tecla >= 48 && tecla <= 57 ) || (tecla == 45 && (elemento.value.search("-") < 0 || (posicao !=undefined && posicao == 0)));
			break;
	
			case "___edt"://editor
			case "___txt"://textarea
			case "___str": // Texto
			break;
	
			case "___psw": // senha
				if ((tecla > 96) && (tecla < 123)) //transformando para maiusculo, 97 = a && 122 = z
					tecla = tecla - 32;
					
				if(!((tecla > 47 && tecla < 58) || ((tecla > 64) && (tecla < 91))) && (tecla != 32)) // Valido p/ numeros e letras
				{
					alert("Este campo só pode ser preenchido com números e letras.");
					ret = false;
				}
			break;
	
			case "___rea"://real
				ret = (tecla >= 48 && tecla <= 57 ) || (tecla == 44) || (tecla == 45) || (tecla == 46);//Digito , - .
			break;
	
			case "___ckb"://checkbox
			case "___rad"://radio
			case "___vet"://vetor
			case "___cor"://cor
			break;
		}
		return ret;
	}
// Verificar qual navegador
function QualNavegador() 
{
	var s = navigator.appName;
	if ( s == "Microsoft Internet Explorer" )
		return "IE";
	else if ( s == "Netscape" )
		return "NE";
	else
		return "";
}
function QualVersao()
{
	var s = navigator.appVersion;
	if ( QualNavegador() == "IE" )
	{
		var i = s.search("MSIE");
		s=s.substring(i+5);
		i=s.search(".");
		return parseInt(s.substring(0,i+1));
	}
	else if ( QualNavegador() == "NE" )
		return parseInt(s.substring(0,1));
	else
		return 0;
}
function verifica_sinal_campo(elemento)
{
	if ( (unformat(elemento.value)*1.0) < 0)
	{
		if (elemento.className != "input_numero_negativo")
		{
			elemento.class_antiga = elemento.className;
			elemento.className = "input_numero_negativo";
		}
	}
	else
	{
		if (elemento.className != "input_numero_negativo")
		{
			elemento.class_antiga = elemento.className;
			elemento.className = elemento.class_antiga;
		}
		else
		{
			elemento.className = "";
		}
	}
}


	function formatar_valor_mascara(tecla,elemento, mascara)
	{
		if(tecla > 47 && tecla < 58) //numeros
		{
			var i = elemento.value.length; 
			var saida = mascara.substring(0,1); 
			var texto = mascara.substring(i);
			
			if(texto.substring(0,1) != "#") 
			{ 
				elemento.value += texto.substring(0,1); 
			}

			if (mascara.substring(0,1) != "#" && elemento.value.substring(0,1) != mascara.substring(0,1))
			{
				elemento.value = mascara.substring(0,1)+elemento.value; 
			}
			
			return true; 
		}
		else
		{ 
			if(tecla != 8) 
			{ 
				return false; 
			}
			else 
			{ 
				return true; 
			}
		}
	}
	
	function VerificaDigitado(evnt)
	{
		switch (this.tipo)
		{
			case "___inm":
				format_inteiro(this);
			break;
		}
	}


	function format_inteiro(num) {
		num = num.toString().replace(/\$|\,/g,'');
		if(isNaN(num))
		num = "0";	
	
		sign = (num == (num = Math.abs(num)));
		num = Math.floor(num*100+0.50000000001);

		num = Math.floor(num/100).toString();
	
		for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
			num = num.substring(0,num.length-(4*i+3))+'.'+num.substring(num.length-(4*i+3));
		var ret = (((sign)?'':'-')+num);
		return ret;
	}
	
	function unformat_inteiro(num) 
	{
		num = num.replace(/\$|\./g,'');
		num = num.replace(/\$|\,/g,'');
		return num;
	}
	

	function format_real(num, casas_decimais) 
	{
		var fator_casa = 1;
	
		if (casas_decimais == "undefined" || isNaN(casas_decimais))
		{
			if (PRECISAO_CASAS_DECIMAIS)
			{
				casas_decimais = PRECISAO_CASAS_DECIMAIS;
			}
			else
			{
				casas_decimais = 2;
			}
		}
		if (casas_decimais > 0)
		{
			fator_casa = 1;
			for (var i = 0; i < casas_decimais; i++)
			{
				fator_casa = fator_casa*10;
			}
		}
	
	
		num = num.toString().replace(/\$|\,/g,'');
		if(isNaN(num))
			num = "0";	
	
		sign = (num == (num = Math.abs(num)));
		num = Math.floor(num*fator_casa+0.50000000001);
	
		cents = num%fator_casa;

		num = Math.floor(num/fator_casa).toString();

		var s = cents+"";
		if(s.length < casas_decimais)
		{
			for (var i = 0; i < casas_decimais-s.length; i++)
			{
				cents = "0" + cents;
			}
		}
	
		for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
			num = num.substring(0,num.length-(4*i+3))+'.'+num.substring(num.length-(4*i+3));
		
		var ret = (((sign)?'':'-')+num);
		if (casas_decimais > 0)
		{
			ret += ',' + cents;
		}
		return ret;
	}
	
	function unformat_real(num) 
	{
		num = num.replace(/\$|\./g,'');
		num = num.replace(/\$|\,/g,'.');
		return num*1.0;
	}

	function filtraCampo(campo){
		var s = "";
		var cp = "";
		vr = campo.value;
		tam = vr.length;
		for (i = 0; i < tam ; i++) {  
			if (vr.substring(i,i + 1) != "/" && vr.substring(i,i + 1) != "-" && vr.substring(i,i + 1) != "."  && vr.substring(i,i + 1) != "," ){
			 	s = s + vr.substring(i,i + 1);}
		}
		campo.value = s;
		return cp = campo.value
	}	
	
	
	
	
	function get_diferenca_datas(date1, date2){

		tmp1 = date1.split(" ");
		tmp2 = date2.split(" ");

		date1 = tmp1[0].split("-");
		date2 = tmp2[0].split("-");
		
		hor1 = new Array("00", "00", "00");
		hor2 = new Array("00", "00", "00");
		if (tmp1[1])
		{
			hor1 = tmp1[1].split(":");
		}
		if (tmp2[1])
		{
			hor2 = tmp2[1].split(":");
		}
		
		var sDate = new Date(date1[0], date1[1], date1[2], hor1[0], hor1[1], hor1[2]);
		var eDate = new Date(date2[0], date2[1], date2[2], hor2[0], hor2[1], hor2[2]);

		var daysApart = Math.abs(Math.round((sDate-eDate)/1000));

		return daysApart;
	}

	function format_sec_to_hor_mim_sec(secs){
		var times = new Array(3600, 60, 1);
		
		var sinal = "";
		if (secs < 0)
		{
			sinal = "-";
			secs = secs*-1;
		}
		
		var time = '';
		var tmp;
		for(var i = 0; i < times.length; i++){
			tmp = Math.floor(secs / times[i]);
			if(tmp < 1){
				tmp = '00';
			}
			else if(tmp < 10)
			{
				tmp = '0' + tmp;
			}
			time += tmp;
			if(i < 2)
			{
				time += ':';
			}
			secs = secs % times[i];
		}
		return sinal+""+time;
	}

	function format_sec_to_hor_mim(secs){
		var ret = format_sec_to_hor_mim_sec(secs);
		ret = ret.substr(0,(ret.length-3));
		return ret;
	}
	function unformat(num) 
	{
		num = num.replace(/\$|\./g,'');
		num = num.replace(/\$|\,/g,'.');
		return num;
	}
