﻿function showFullscreen(url)
{
	height = screen.availHeight;
	width = screen.availWidth;
	
	// Windows 2k fix
	if(navigator.userAgent.indexOf('Windows NT 5.0') != -1)
	{
		height = height - 20;
		width = width - 10;
	}

	try
	{
		tmp = window.open(url, 'tmp', "height=" + height + "px,width=" + width + "px,top=0,left=0,location=0,menubar=0,resizable=0,scrollbars=0,toolbar=0");
		tmp.resizeTo(width, height);
	}
	catch(e) {;}
}

function showNormal(url)
{	
	try
	{
		tmp = window.open(url, '', "height=" + screen.availHeight + "px,width=" + screen.availWidth + "px,top=0,left=0,location=1,menubar=1,resizable=1,scrollbars=1,toolbar=1");
		tmp.resizeTo(screen.availWidth,screen.availHeight);
	}
	catch (e) {;}
}

function maximizeCurrentWindow()
{
	try
	{
		top.window.moveTo(0,0);
		
		if (document.all)
		{
			var newWidth = screen.availWidth;
			var newHeight = screen.availHeight;
			
			top.window.resizeTo(newWidth, newHeight);
			
			shouldRemove = false;
			if(window.screenTop < 0)
			{
				newHeight = screen.availHeight - window.screenTop;
				shouldRemove = true;
			}
			
			if(window.screenLeft < 0)
			{
				newWidth = screen.availWidth - window.screenLeft;
				shouldRemove = true;
			}
				
			if(shouldRemove)
			{
				top.window.resizeTo(newWidth, newHeight);
				top.window.moveTo(0,0)
			}
		}
		else if (document.layers || document.getElementById)
		{
			if (top.window.outerHeight<screen.availHeight || top.window.outerWidth<screen.availWidth){
				top.window.outerHeight = screen.availHeight;
				top.window.outerWidth = screen.availWidth;
			}
		}
	}
	catch (e) {}
}

function ipaperClose()
{
	if(parent)
		parent.close();
	else
		window.close();
}

function getFlashVersion()
{
	var flashversion = 0;
	
	try
	{
		if(navigator.plugins && navigator.mimeTypes.length)
		{
			var x = navigator.plugins["Shockwave Flash"];
			
			if(x && x.description)
				flashversion = x.description.replace(/([a-z]|[A-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split(".");
		}
		else if (window.ActiveXObject)
		{
			try
			{
				var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
				flashversion = axo.GetVariable("$version").split(" ")[1].split(",");
			}
			catch (e) {}
		}
	}
	catch (e) {}
	
	return flashversion;
}

function printImg(imageUri)
{
    var img = new Image();
    img.src = imageUri + '#' + Math.floor(Math.random() * 10000);
    img.onload = scalePrintImage;
}

function scalePrintImage()
{
    var newWidth = this.width;
    var newHeight = this.height;

    var maxWidth = 650;
    var maxHeight = 900;

    // Scale
    if (this.width > maxWidth)
    {
    	var scalePercentage = maxWidth / newWidth;
    	newWidth = maxWidth;
        newHeight = this.height * scalePercentage;
    }
    
    if (newHeight > maxHeight)
    {
    	var scalePercentage = maxHeight / newHeight;
    	newHeight = maxHeight;
        newWidth = newWidth * scalePercentage;
    }

    document.getElementById('imgPrint').style.width = newWidth;
    document.getElementById('imgPrint').style.height = newHeight;
    document.getElementById('imgPrint').src = this.src;
}