//PERMISSAO
function permissionDenied(pagina){
	alert('Você não possui acesso a esta parte.');
	if (window.opener){
		window.opener.focus();
		window.close();
	}
	else{
		history.back();
	}
}

//Toggle Display
function tDisp(obj){obj.style.display=(obj.style.display=='none'?'inline':'none');}

//	FECHAR JANELAS
//	refresh = Se deve recarregar a pagina anterior (PADRAO TRUE)
function fechar(refresh){

	if (refresh!=0) refresh=1;
	if (window.dialogWidth){
		self.close();
		if (refresh && dialogArguments==window){
			dialogArguments.location.reload()
		}
	}
	else{
		window.close();
		if(window.opener && !window.opener.closed){
			if (refresh) window.opener.location.reload();
			window.opener.focus();
		}
	}
}

function newPopup(url,params,feat){
	
	if (feat==undefined) feat='features=no,status=yes,scrollbars=yes,resizable=yes';
	if (params==undefined) params='';
	if (url!=undefined){
	//	if (window.showModalDialog){
	//		return (window.showModalDialog(url,window+','+params,feat));
	//	}
	//	else{
			return(window.open(url,params,feat));
	//	}
	}
}

function autoText(texto){
	if(confirm('Deseja inserir uma nova premissa?\n(Caso contrário, será inserido um alerta).'))
		newPopup('http://www.wwow.com.br/edoc/planilhas/cad_premissas.asp?objetivo='+texto);
	else
		newPopup('http://www.wwow.com.br/edoc/alertas/alerta_paciente.asp?text='+texto);
}

// Window Resizer - Based on TD STYLE height - OK for SP2 Fuckin Status Bar shit
//	a = # of Titles
//	b = # of Namings
//	c = # of Fats or Vals
// 	w = Desired width
// 	h = Desired height
//  dialog = (DEPRECATED) if is dialogWindow
function sizeme(a,b,c,w,h,dialog){
	/* DEFAULT TD HEIGHTS */
	var title=23;
	var naming=31;
	var fat=22;
	var space=120;
	/* RESIZER & CENTERER */
	if (!h)	h=((a*title)+(b*naming)+(c*fat)+space);
	if (h>screen.height) h=screen.height;
	if (window.dialogWidth){
		//alert('DIALOG');
		dialogWidth=(w+'px');
		dialogHeight=(h+'px');
		dialogLeft=(screen.width/2-w/2);
		dialogTop=(screen.height/2-h/2);
	}
	else{
		//alert('WINDOW');
		moveTo(0,0);
		window.resizeTo(w,h);
		moveTo((screen.width-w)/2,(screen.height-h)/2);
	}
}

function alertSize() {

}

function sizeTo(w,h){
	moveTo(0,0);
	window.resizeTo(w,h);
	moveTo((screen.width-w)/2,(screen.height-h)/2);
}

function pre_select(obj,valor_selecionado){
	//	PRESELECIONADOR DE SELECTS
	//	obj = objeto inteiro ('document.form1.select') COM OU SEM aspas.
	//	valor_selecionado = Valor do item a ser selecionado (especificado no VALUE do option)
	if (typeof(obj)=='string') obj=eval(obj);
	for(i=0;i<obj.length;i++){
		if (obj.options[i].value==valor_selecionado){
			obj.options[i].selected=1;
			break;
		}
	}
}

function pre_radio(obj,valor_selecionado){
	for(i=0;i<obj.length;i++){if (obj[i].value==valor_selecionado){obj[i].checked=1;break;}}return i;
}

function get_radio(obj){
	for(i=0;i<obj.length;i++) if (obj[i].checked) return obj[i].value; return false;
}

//	PRESELECIONADOR DE CHECKBOXES
//	obj = objeto inteiro ('document.form1.select') COM OU SEM aspas.
//	valores = Valores dos itens a serem selecionados (NAO ACEITA TEXTO!!!)
function pre_checkbox(obj,valores){
	var indexes=new Array();
	valores=valores.split(',');
	if (typeof(obj)=='string') obj=eval(obj);
	for(j=0;j<obj.length && valores.length>0;j++){
		for(i=0;i<valores.length;i++){
			if (+obj[j].value==+valores[i]){
				valores.splice(i,1);
				obj[j].checked=1;
				indexes.push(j);
			}
		}
	}
	return indexes;
}


//Verifica se o tamanho máximo de um textArea foi atingido
//obj - objeto inteiro
function ismaxlength(obj){
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")):"";
	
	if (obj.getAttribute && obj.value.length>mlength)
		obj.value=obj.value.substring(0,mlength);
}

