String.prototype.trim = function(){
	return this.replace(/^\s+|\s+$/g,'');}

// String.isEmpty ()
String.prototype.isEmpty = function(){
	return this.split(" ").join("").length == 0;}

// String.isEmail ()
String.prototype.isEmail = function(){
	var er = /^[a-z0-9._-]+@([a-z0-9]+[a-z0-9_-]*)+(\.[a-z0-9]+)+$/;
	return er.test(this);}

// String.IsNumeric()
String.prototype.isNumeric = function ()
{
	var testaNumero = /[^0-9]+$/;
	return testaNumero.test(this);
}

// strin.IsDate()
String.prototype.isDate = function () 
{
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
	return datePat.test(this);
}

mostrarEsconderObj = function(obj){
	objeto = document.getElementById(obj);
	if ( objeto.style.display == 'block'){
		objeto.style.display = 'none';
	}else{
		objeto.style.display = 'block';
		
		var id_msg = obj;
		var id_ancora = id_msg.split("-");
		
		if (document.getElementById(id_ancora[2])){
			document.getElementById(id_ancora[2]).focus();	
		}
		
		
	}	
}

/**
 * Validar a pagina de consulta para salas disponíveis para reservar.
 * 
 * @param {Object} target
 * @param {Object} txtAlerta
 * @param {Object} txtFrm
 */
function alertar(target,txtAlerta,txtFrm){
	var frm = document.getElementById(txtFrm);
	var corAlerta = '#FFEEEE';
	alert(txtAlerta);
	eval('frm.'+target+'.focus()');
	eval('frm.'+target+'.style.backgroundColor=corAlerta');
	return false;
}

/**
 * Validação do Formulário de Insert e Update de Mensagens
 * 
 * @param {object} obj
 * @return boolean
 */
function validarMensagem(obj){

	var corAlerta = '#FFEEEE';
	var frm = document.getElementById(obj.id); 
	
	if (frm.txt_titulo.value.isEmpty())
		return alertar('txt_titulo','Preencha o campo Titulo.',obj.id);
	else 
		frm.txt_titulo.style.backgroundColor='#ffffff';
	
	if ( ! obj.id == "form-mensagem-alt" ){ 

		if ( ! frm.txa_mensagem.value != "")
			return alertar('txa_mensagem','Preencha o campo Mensagem.',obj.id);
		else 
			frm.txa_mensagem.style.backgroundColor='#ffffff';
	}
	if (frm.sel_categoria.value == 0)
		return alertar('sel_categoria','Escolha uma categoria.',obj.id);
	else 
		frm.sel_categoria.style.backgroundColor='#ffffff';
		
	if ( frm.file_msgfoto.value != "" ){
		
		var array_value_file = frm.file_msgfoto.value.split(".");
		var ext = array_value_file[array_value_file.length - 1];
		
		if ( ext.toLowerCase() != "jpg" ){

			return alertar('file_msgfoto','Só é permitido fotos com extenção JPG.',obj.id);
			
		}else{
			
			frm.file_msgfoto.style.backgroundColor='#ffffff';
		}
		
		
		
	}
		
}	

/**
 * Validação do Formulário de Insert e Update de Categorias
 * 
 * @param {objeto} obj
 */
function validarCategoria(obj){

	var corAlerta = '#FFEEEE';
	var frm = document.getElementById(obj.id); 
	
	if (frm.txt_categoria.value.isEmpty())
		return alertar('txt_categoria','Preencha o campo Categoria.',obj.id);
	else 
		frm.txt_titulo.style.backgroundColor='#ffffff';
	
}

/**
 * Validação do Formulário de Insert e Update do Blog
 * 
 * @param {object} obj
 * @return boolean
 */
function validarBlog(obj){
	

	
	var corAlerta = '#FFEEEE';
	var frm = document.getElementById(obj.id); 
	
	if (frm.txt_blogtitulo.value.isEmpty())
		return alertar('txt_blogtitulo','Preencha o campo Titulo.',obj.id);
	else 
		frm.txt_blogtitulo.style.backgroundColor='#ffffff';
	
	if (frm.txt_blogassinatura.value.isEmpty())
		return alertar('txt_blogassinatura','Preencha o campo Assinatura.',obj.id);
	else 
		frm.txt_blogassinatura.style.backgroundColor='#ffffff';
	
	if (frm.txa_blogdescricao.value.isEmpty())
		return alertar('txa_blogdescricao','Preencha o campo Descrição.',obj.id);
	else 
		frm.txa_blogdescricao.style.backgroundColor='#ffffff';	

	marcado = -1

	for (i=0; i<frm.rda_blogestilo.length; i++) {
	
		if (frm.rda_blogestilo[i].checked) {
			marcado = i;
			radio = frm.rda_blogestilo[i].value;
		}
	
	}
	
	if (marcado == -1) {
		alert("Selecione um ESTILO.");
		frm.rda_blogestilo[0].focus();
		return false;
	}	
		
	if ( frm.rda_blogestilo.checked == false)
		return alertar('rda_blogestilo','Escolha um Estilo.',obj.id);
	else 
		frm.rda_blogestilo.style.backgroundColor='#ffffff';
}	

/**
 * Validação do Formulário de Insert e Update de Categorias
 * 
 * @param {objeto} obj
 */
function validarLinks(obj){

	var corAlerta = '#FFEEEE';
	var frm = document.getElementById(obj.id); 
	
	if (frm.txt_link.value.isEmpty())
		return alertar('txt_link','Preencha o campo Link.',obj.id);
	else 
		frm.txt_link.style.backgroundColor='#ffffff';
		
	if (frm.txt_linkurl.value == "http://")
		return alertar('txt_linkurl','Preencha o campo ULR.',obj.id);
	else 
		frm.txt_linkurl.style.backgroundColor='#ffffff';	
	
}

/**
 * Validação do Formulário de Insert Comentários
 * 
 * @param {objeto} obj
 */
function validarComentario(obj){

	var corAlerta = '#FFEEEE';
	var frm = document.getElementById(obj.id); 
	
	if (frm.txt_autorcomentario.value.isEmpty())
		return alertar('txt_autorcomentario','Preencha o campo Nome.',obj.id);
	else 
		frm.txt_autorcomentario.style.backgroundColor='#ffffff';
	
	if ( ! frm.txt_emailcomentario.value.isEmail())
		return alertar('txt_emailcomentario','O campo e-mail está incorreto.',obj.id);
	else 
		frm.txt_emailcomentario.style.backgroundColor='#ffffff';	
		
	if (frm.txa_comentario.value.isEmpty())
		return alertar('txa_comentario','Preencha o campo Comentario.',obj.id);
	else 
		frm.txa_comentario.style.backgroundColor='#ffffff';	
	
}

validarRegras = function(){
	
	var corAlerta = '#FFEEEE';
	var frm = document.getElementById("form-regras"); 
	
	if ( ! frm.chk_aceito.checked){
		return alertar('chk_aceito','Preencha o campo "Aceito as regras acima e desejo criar meu blog."','form-regras');
	}else{ 
		window.location.href = 'blog.criar.php';
	}	
}

$j(document).ready(function(){
	
	/*$j('#txt-expressao').bind('keyup', function() {
		
		$j.post('<?php echo DOMINIO;?>/black-list/ajax_verify_field.php', {'txt_expressao':$j(this).attr("value")}, function(data){
			
			$j('#ajax-result').html(data);
			
			if ( data == 1 ){
				$j('#txt-expressao').css("border-color","#FF0000");
				$j('#field-mensagem').html("A Expressão digitada já exite!!");			
				$j('#field-mensagem').show();			
			}else{
				$j('#txt-expressao').css("border-color","#88B7D2");
				$j('#field-mensagem').html("");	
				$j('#field-mensagem').hide();
			}
			
		});
		
		/*$j('<div id="loading"><img src="ajax-loader.gif" alt="loading..." /></div>')
			.insertBefore('#teste')
			.ajaxStart(function() {
				$j(this).show();
				$j(this).html("");
			}).ajaxStop(function() {
				$j(this).html("");
				$j(this).hide();
			});*/
		
		
		//return false;
	});*/
	
});



