//alert(Math.round(2.7));
//alert(2.7);
var var_image_file;
var titulo_janela;
function abre_imagem(image_file, var_titulo_janela) {
	abre_imagem_titulo(image_file, ":");
}

function abre_imagem_titulo(image_file, var_titulo_janela) {
	var_image_file = image_file;
	titulo_janela = var_titulo_janela;
	abre_imagem_consulta("image_dinamic_consulta_imagem.aspx?path_imagem_virtual=" + image_file);
}

function abre_imagem_resultado_consulta() { 
	if (xmlHttp.readyState == 4) { 
		var tamanho = xmlHttp.responseText.split('_');
		var height = tamanho[0];
		var width = tamanho[1];
		abre_imagem_grande(width, height, var_image_file, titulo_janela);
	}
}

function abre_imagem_grande(v_width_imagem, v_height_imagem, image_file, titulo) {
	var width_imagem = v_width_imagem;
	var height_imagem = v_height_imagem;
	try {
		w_limite = window.screen.width - 75
		h_limite = window.screen.height - 75;
	}
	catch(e) {
		w_limite = 620;
		h_limite = 460;
	}
	if (width_imagem > w_limite) {
		height_imagem *= w_limite;
		height_imagem /= width_imagem; 
		width_imagem = w_limite;
	}
	if (height_imagem > h_limite) {
		width_imagem *= h_limite;
		width_imagem /= height_imagem; 
		height_imagem = h_limite;
	}
	width_imagem = Math.round(width_imagem);
	height_imagem = Math.round(height_imagem);
	var url = "image_dinamic_grande.aspx?image_file=" + image_file + "&titulo=" + titulo + "&width=" + width_imagem + "&height=" + height_imagem;
	openDialog(width_imagem, height_imagem, url);
}

function getTopPos(pHeight){return (screen.height)?(screen.height-pHeight)/2 - 35:0;}
function getLeftPos(pWidth){return (screen.width)?(screen.width-pWidth)/2:0;}
function openDialog(pW, pH, pURL){window.open(pURL, "", "top="+getTopPos(pH)+",left="+getLeftPos(pW)+",width="+pW+",height="+pH+",statusbar=yes,toolbar=no,resizable=no,scrollbars=no");}


var xmlHttp;
var nome_obj_html;

function abre_imagem_consulta(url) { 
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert ("Your browser does not support AJAX!");
		return;
	} 
	//var url = "teste2.aspx";
	//url += "?q=" + str;
	try {
		var reg1str = "\\?";
		var reg1 = new RegExp(reg1str);
		if (!reg1.test(url)) {
			url += "?sidrand=" + Math.random();
		}
		else {
			url += "&sidrand=" + Math.random();
		}
	}
	catch (err) {
	}
	xmlHttp.onreadystatechange = abre_imagem_resultado_consulta;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}
function GetXmlHttpObject() {
	var xmlHttp = null;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	}
	catch (e) {
		// Internet Explorer
		try  {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

