/************************************************************
Funções Genericas - goshme

*************************************************************/

/**
 * Declare an object to which we can add real functions.
 */
if (goshme == null) var goshme = {};
if (goshme.custom == null) goshme.custom = {};
if (GoshmeCustom == null) var GoshmeCustom = goshme.custom;

goshme.custom.getVerbete = function (query,check,e){
	var param;
	var iq = document.getElementById('form_dic').q;
	if(query==null){
		query = iq.value;
	}else{
		iq.value = query;
	}
	param = 'op=dicionario&q='+encodeURIComponent(query.toLowerCase());
	if(check != null){
		param += '&openBalaoDicionario='+encodeURIComponent(check);
		showBalaoDicionario(e,query,null,null,null);
	}
   
	goshme.util.setValue('verbete','<p><em>Buscando defini&ccedil;&atilde;o...</em></p>');
	goshme.util.sendRequest('../../ajax', param,'POST');
	
	return false;
}



goshme.custom.getCitacaoSnippet = function (codeCitacao, idCatalog, codeDiv){
	var param = 'op=citacao_legis&codeCitacao='+codeCitacao+'&codeDiv='+codeDiv+'&item='+idCatalog;
	goshme.util.sendRequest('../..//ajax', param,'POST');
	return false;
}


goshme.custom.getSelText = function(e,check) {
    var txt = '';
	try{
    	if (window.getSelection) { //mozilla
			var range = window.getSelection().getRangeAt(0);
			var clonedSelection = range.cloneContents();
	    	var div = document.createElement('div');
	    	div.appendChild(clonedSelection);
	    	txt = div.innerHTML;
    	}
		else if (document.selection) { //ie
			txt = document.selection.createRange().htmlText;
    	}
    	else return;
	}catch(e){}
	txt = txt.replace(/<\/?[^>]+(>|$)/g, "");
	txt = txt.replace(/[\W[^çÇáéíóúàèìòùÁÉÍÓÚÀÈÌÒÙãõÃÕäëïöüÄËÏÖÜâêîôûÂÊÎÔÛ]]/g, "");
	//txt = txt.replace(/[\w\S\/\-\+\.\,\*\\?!\(\)\%\#\:\;\{\}\[\]\-\_\+\=\'\"]/g, "");
	
	if(txt != ""){
		goshme.custom.getVerbete(txt,check,e);
	}
}


goshme.custom.zoomText = function (container, size, el){
	var text = document.getElementById(container);
	if(size < 0){ size = 80; }
	else if (size > 0) {size = 120;}
	else{ size = 100; }
	text.style.fontSize = size+'%';
	if(el!=null){
		
		var as = document.getElementById('aaa');
		var lis = as.getElementsByTagName('a');
		for(i=0;i<lis.length;i++){
			//if(lis == el){
				
		//	}else{
				var regex = new RegExp("(^|\\s)bold black(\\s|$)", 'g');
				lis[i].className = lis[i].className.replace(regex, '');
			//}						
		}
		el.className += " bold black";
	}
}

goshme.custom.highlight = function (on, node) {
	if(node!=null){
		node.className=on?'hlon':'hloff';
		node.innerHTML=on?'Desmarcar texto':'Marcar Texto';
		node.onclick =  function() {goshme.custom.highlight(!on, node);};
	}
	var spans = document.getElementsByTagName('span');
	for(var i=0; i< spans.length; i++){
		if(spans[i].className == 'hlon' || spans[i].className == 'hloff'){
			 spans[i].className=on?'hlon':'hloff';	
		}
	}
}

