// JavaScript Document
function doBusca(){
	var busca = document.getElementById('BuscaBox').value;
	//alert(busca);
	if(busca.length  <= ''){
		alert(busca+" Busca está vazia");
	}else{
		document.forms.bbox.submit();
	}
}
function clearCampo(id){
	document.getElementById(id).value = '';
}
function doCad(){
	document.location.href = '../info/cadastro.php?NO_LAYOUT=TRUE';
}
function doSenha(){
	document.location.href = '../info/senha.php?NO_LAYOUT=TRUE';
}
function doCompra(arglink){
	document.location.href = '../info/catalogo.php?'+arglink;
}
// Artistas
function doSelArtist(){
	//var arti = document.getElementById('arti0_cod').options[document.getElementById('arti0_cod').selectedIndex].value;
	document.getElementById('faz').value = "selArt";
	//document.getElementById('submitter').click();
	document.mydados.submit();
}
function confirmaDelete(cod,cod2) {
	var cf = confirm("Deseja mesmo excluir esta obra?");
	if(cf) document.location.href = "adm_galerias_obra.php?acao=delete&obra0_cod=" + cod + "&gale0_cod=" + cod2;
}
function openNew(){
	if(document.getElementById('novaobra').style.display == 'none'){
		document.getElementById('novaobra').style.display = 'block';			
		document.getElementById('novaobra').style.visibility = 'visible';
		document.getElementById('add_cancel').innerHTML  = 'Cancelar Inclusão de obras';
	}else{
		document.getElementById('novaobra').style.display = 'none';			
		document.getElementById('novaobra').style.visibility = 'hidden';
		document.getElementById('add_cancel').innerHTML  = 'Adicionar obra';
	}
}
function vf(xform){
	var formulario = xform;
	var errmsg = '';
	var errmsg = Array();
	
	if(formulario.autor.value == '') errmsg.push(" - Artista da Obra não foi definido");
	if(formulario.titulo.value == '') errmsg.push(" - Título da Obra não foi definido");
	if(formulario.tecnica.value == '') errmsg.push(" - Técnica da Obra não foi definido");
	if(formulario.ano.value.length < 4) errmsg.push(" - Ano da Obra não foi definido corretamente");
	//if(formulario.credito.value == '') errmsg.push(" - O Crédito da imagem não foi definido");
	//if(formulario.medida_a.value == 'altura' || formulario.medida_l.value == 'largura' || formulario.medida_p.value == 'profund.') errmsg.push(" - As medidas da obra não estão definidas corretamente");
	
	if(errmsg.length > 0 ){
		alert('Verifique os erros abaixo:\n\n' + errmsg.join("\n"));
		return false;
	}
	
	if(formulario.medida_a.value == 'altura') { formulario.medida_a.value = ""; formulario.medida_a.disabled = true; }
	if(formulario.medida_l.value == 'largura') { formulario.medida_l.value = ""; formulario.medida_l.disabled = true; }
	if(formulario.medida_p.value == 'profund.') { formulario.medida_p.value = ""; formulario.medida_p.disabled = true; }
	
	return true;
}
//$(document).ready(function() {
//	$(".medidas").focus( function() {
//		if(isNaN(this.value)) this.value="";
//		$(this).css("color","black");
//	});
//	
//	$("#med_a").blur( function() {
//		if(this.value=="") {
//			$(this).css("color","#aaaaaa");
//			this.value="altura";
//		}
//	}).blur();
//	
//	$("#med_l").blur( function() {
//		if(this.value=="") {
//			$(this).css("color","#aaaaaa");
//			this.value="largura";
//		}
//	}).blur();
//	
//	$("#med_p").blur( function() {
//		if(this.value=="") {
//			$(this).css("color","#aaaaaa");
//			this.value="profund.";
//		}
//	}).blur();
//});   
function doShow(){
	document.getElementById('trnew').style.display = 'block';
}
function go(ref){
    window.location ='#' + ref;
}
function show(){
	document.getElementById('princ').style.visibility = 'visible';
	document.getElementById('princ').style.display = 'block';
}
function vf2(){
	var nom1 = document.getElementById('arti0_nom_alt').value;
	var nom2 = document.getElementById('nome').value;
	if(nom1 != nom2){
		//if(confirm("O nome do artista mudou, voce quer mesmo alterar o nome do artista?" )){
			return true;
		//}else{
		//	return false;
		//}
	}else{
		return true;
	}	
}
function addNew(){
	document.getElementById('nome').value = '';
	document.getElementById('biografia').value = '';
	document.getElementById('arti0_cod').value = 999999;
}
function suggest(inputString){
	if(inputString.length == 0) {
		$('#suggestions').fadeOut();
	} else {
		$('#nome').addClass('load');
		$.post("arti0_suggest.php", {queryString: ""+inputString+""}, function(data){
			if(data.length >0) {
				$('#suggestions').fadeIn();
				$('#suggestionsList').html(data);
				$('#nome').removeClass('load');
			}
		});
	}
}
function fill(thisValue) {
	$('#nome').val(thisValue);
	setTimeout("$('#suggestions').fadeOut();", 600);
}

// Artistas End
function str_replace (search, replace, subject, count) {
	var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
			f = [].concat(search),
			r = [].concat(replace),
			s = subject,
			ra = r instanceof Array, sa = s instanceof Array;
	s = [].concat(s);
	if (count) {
		this.window[count] = 0;
	}

	for (i=0, sl=s.length; i < sl; i++) {
		if (s[i] === '') {
			continue;
		}
		for (j=0, fl=f.length; j < fl; j++) {
			temp = s[i]+'';
			repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
			s[i] = (temp).split(f[j]).join(repl);
			if (count && s[i] !== temp) {
				this.window[count] += (temp.length-s[i].length)/f[j].length;}
		}
	}
	return sa ? s : s[0];
}
function printPartOfPage(elementId){
 var printContent = document.getElementById(elementId);
 var windowUrl = 'about:blank';
 var windowName = 'Print' + new Date().getTime();
 var printWindow = window.open(windowUrl, windowName, 'left=0,top=0,width=0,height=0');
 printWindow.document.write(printContent.innerHTML);
 printWindow.document.close();
 printWindow.focus();
 printWindow.print();
 printWindow.close();
}
function printSelection(node){
  var content=node.innerHTML
  var pwin=window.open('','print_content','width=100,height=100');
  pwin.document.open();
  pwin.document.write('<html><body onload="window.print()">'+content+'</body></html>');
  pwin.document.close();
  setTimeout(function(){pwin.close();},1000);
}

