function getImage(pExistingImageID, pImageURL, max_width, max_height)
{
    var img = document.createElement('img');
	max_width = max_width - 60;
	max_height = max_height - 70;
	
    img.onload = function (evt) 
	{
        document.getElementById(pExistingImageID).src=this.src;
		
		var height = this.height;
		var width = this.width;
		var ratio = height/width;
	
		if(height > max_height)
		{
			ratio = max_height / height;
			height = height * ratio;
			width = width * ratio;
		}
	
		if(width > max_width)
		{
			ratio = max_width / width;
			height = height * ratio;
			width = width * ratio;
		}
	
        document.getElementById(pExistingImageID).width = width;
        document.getElementById(pExistingImageID).height = height;
        document.getElementById(pExistingImageID).style.width = width;
        document.getElementById(pExistingImageID).style.height = height;
    }
    img.src = pImageURL;
    return false;
}
var y = 0;
function show_image_fullscreen(i)
{
	var browser = navigator.appName;
	len = i.length;
	i = i.substr(0, len - 4) + 'b' + i.substr(len - 4);
	document.getElementById('tb_negru').style.height = "100%";
	document.getElementById('tb_negru').style.width = "100%";
	if(browser != "Microsoft Internet Explorer")
	{
		document.getElementById('img_fulscreen').src = 'images/imag/loading.gif';
		value = 8;
		document.getElementById('tabel_peste').style.opacity = value/10;
		document.getElementById('tabel_peste').style.filter = 'alpha(opacity=' + value*10 + ')';
		document.getElementById('tabel_peste').style.display = 'inline';
		document.getElementById('tabel_poza').style.display = 'inline';
		getImage('img_fulscreen', i, window.innerWidth, window.innerHeight);
	}
	else
	{
		y = document.body.scrollTop;
		document.getElementById('img_fulscreen').src = 'images/imag/loading.gif';
		value = 8;
		document.getElementById('tabel_peste').style.opacity = value/10;
		document.getElementById('tabel_peste').style.filter = 'alpha(opacity=' + value*10 + ')';
		document.getElementById('tabel_peste').style.display = 'inline';
		document.getElementById('tabel_poza').style.display = 'inline';
		document.getElementById('tabel_poza').style.position = 'absolute';
		document.getElementById('tabel_principal').style.display = 'none';
		getImage('img_fulscreen', i, document.body.offsetWidth, document.body.offsetHeight);
	}
}
function hide_image_fullscreen()
{
	var browser = navigator.appName;
	i = 'images/imag/loading.gif';
	document.getElementById('tabel_peste').style.display = 'none';
	document.getElementById('tabel_poza').style.display = 'none';
	document.getElementById('img_fulscreen').src = i;
	document.getElementById('img_fulscreen').style.width = 32;
	document.getElementById('img_fulscreen').style.height = 32;
	if(browser == "Microsoft Internet Explorer")
	{
		
		document.getElementById('tabel_principal').style.display = 'inline';
		document.getElementById('tabel_poza').style.position = 'fixed';
		window.scrollTo(document.body.scrollLeft, y);
	}
}
function Key_Code_Work(e)
{
	key = e.keyCode;
	switch(key)
	{	
		case 27: 
				if (document.getElementById('img_fulscreen').src != 'images/imag/loading.gif')
				{
					hide_image_fullscreen();
				}
				break;
	}
}

