var global_print_contentbox = false;

function callSearch(){
	var keysea = document.getElementById('index_id_search_key');
	if(!validaCampo('index_id_search_key', 'input', 'Informe o termo que deseja buscar.', 'Digite o que deseja buscar', false, false)){
		return false;
	}
	if(keysea.value.length<=2){
		alert("O termo de busca não pode conter menos que 3(três) caracteres.");
		keysea.select();
		keysea.focus();
		return false;
	}
	window.location = '?h_pg=search&keyword='+keysea.value;
}

function recommendedPage(){
	var alobjs = "recp_emaildestinatario,recp_nomeproprio,recp_emailproprio,recp_comentario,cc_tomy";

	var email_destino = document.getElementById('recp_emaildestinatario');
	var meu_nome = document.getElementById('recp_nomeproprio');
	var meu_email = document.getElementById('recp_emailproprio');
	var comentario = document.getElementById('recp_comentario');
	var receber_copia = document.getElementById('cc_tomy');
	
	if(!validaCampo('recp_emaildestinatario', 'input', 'O campo "E-mail do destinatário" precisa ser preenchido.', false, 'email', 'O campo "E-mail do destinatário" precisa ser preenchido corretamente.')){
		return false;
	}
	if(!validaCampo('recp_nomeproprio', 'input', 'O campo "Meu nome" precisa ser preenchido.', false, false, false)){
		return false;
	}	
	if(!validaCampo('recp_emailproprio', 'input', 'O campo "Meu e-mail" precisa ser preenchido.', false, 'email', 'O campo "Meu e-mail" precisa ser preenchido corretamente.')){
		return false;
	}	
	if(!validaCampo('recp_comentario', 'textarea', 'O campo "Comentário" precisa ser preenchido.', false, false, false)){
		return false;
	}
	
	var fn_receber_copia = 0;
	if(receber_copia.checked==true) fn_receber_copia = 1;
	
	disableEnableFields('disable', alobjs);
	loading(1);
	
	var values = "";
	values+= "email_destino="+email_destino.value;
	values+= "&meu_nome="+meu_nome.value;
	values+= "&meu_email="+meu_email.value;
	values+= "&comentario="+comentario.value;
	values+= "&receber_copia="+fn_receber_copia;
	window.recPageResultadoEnvia = function(r){
		r = unescape(r);
		if(r=="1"){
			loading(0);
			windmal_content('finished', 'Obrigado!', false, 1, 'Sua recomendação foi enviada!', false, false, false);
			return true;
		} else {
			alert("Não foi possível atender sua solicitação.\nO erro retornado foi:\n\n"+r);
			disableEnableFields('enable', alobjs);
			loading(0);
			return false;
		}
	}
	saveServer(values, '?control=ajax&name=mail', 'recPageResultadoEnvia');	
	
}

function pageButtons(toDisable){
	var index_boxonpagebuttons = document.getElementById('index_boxonpagebuttons');
	var buttons_noinc_class = "sep";
	var allbuttons = index_boxonpagebuttons.getElementsByTagName('img');
	for(var i=0; i<allbuttons.length; i++){
		if(!in_array(buttons_noinc_class, allbuttons[i].className)) allbuttons[i].className = "normal";
		if(toDisable && in_array(toDisable, allbuttons[i].alt)) allbuttons[i].className = "disabled";
	}
}

function openServiceButton(me){
	if(!me || me.className == "disabled") return false;
	switch(me.id){
		case "pagebutton_pdf":
			alert("Serviço para gerar pdf.");
		break;
		case "pagebutton_print":
			includeCSS("views/index/css/window.print.css");
			windmal(600, 400, 'Imprimir (Beta)', 'print_frame(\'print_frame\')', '?control=ajax&name=getpage&view=index&file=print_window.html');
			window.print_frame = function(frame_id){
				var frame_o = document.getElementById(frame_id);
				var frame_name = frame_o.name;
				window.print_loadedframe = function(){
					if(global_print_contentbox && document.getElementById(global_print_contentbox)) wordData = document.getElementById(global_print_contentbox).innerHTML;
					else wordData = document.getElementById('index_contentpage').innerHTML; 
					wordData = removeTags(wordData, 'a');
					frame_o.contentWindow.document.getElementById('print_id_contentallcon').innerHTML = wordData;
				}
				return true;
			}
		break;
		case "pagebutton_mail":
			windmal(300, 275, 'Recomendar página', '', '?control=ajax&name=getpage&view=index&file=pagetomail.html');
		break;
		default:
			alert("Error! Buttons of Page: Identificador de validação inválido.");
			return false;
	}
	return true;
}

function printServiceChangeContentId(id_content){
	var button_print = document.getElementById('pagebutton_print');
	var objc = document.getElementById(id_content);
	global_print_contentbox = id_content;
}