﻿
if (/msie/i.test (navigator.userAgent)) //only override IE
{
	document.nativeGetElementById = document.getElementById;
	document.getElementById = function(id)
	{
		var elem = document.nativeGetElementById(id);
		if(elem)
		{
			//make sure that it is a valid match on id
			if(elem.id == id)
			{
				return elem;
			}
			else
			{
				//otherwise find the correct element
				for(var i=1;i<document.all[id].length;i++)
				{
					if(document.all[id][i].id == id)
					{
						return document.all[id][i];
					}
				}
			}
		}
		return null;
	};
}

function isNumberKey(e)
{
     var unicode = e.charCode ? e.charCode : e.keyCode;
     if(unicode != 8) {
        if(unicode < 48 || unicode > 57) {
            return false;
        }
     }
            
}

function closeLogin() {
    document.body.style.overflow = "auto";
    document.getElementById('login').style.display = "none";
}

function getPosition(e) {
    e = e || window.event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    } 
    else {
        var de = document.documentElement;
        var b = document.body;
        cursor.x = e.clientX + 
            (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = e.clientY + 
            (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    }
    return cursor;
}


function openPreview(e, source) {
    document.body.style.overflow = "hidden";
    var preview = document.getElementById('preview');
    document.getElementById('previewimagepopup').src = source.src;
    preview.style.visibility = "visible";    
    preview.style.width = "320";
    preview.style.height = "240";
    preview.style.left = (getPosition(e).x + 10);
    preview.style.top = getPosition(e).y - 140;
    
}



function closePreview() {
    //document.body.style.overflow = "auto";
    document.getElementById('preview').style.visibility = "hidden";
}

function openLogin() {
    document.body.style.overflow = "hidden";
    var login = document.getElementById('login');
    login.style.display = "";
    login.style.width = f_clientWidth(); 
    login.style.height = f_clientHeight();
    login.style.left = f_scrollLeft();
    login.style.top = f_scrollTop();
    
}

function closeLogout() {
    document.body.style.overflow = "auto";
    document.getElementById('logout').style.display = "none";
}

function openLogout() {
    document.body.style.overflow = "hidden";
    var logout = document.getElementById('logout');
    logout.style.display = "";
    logout.style.width = f_clientWidth(); 
    logout.style.height = f_clientHeight();
    logout.style.left = f_scrollLeft();
    logout.style.top = f_scrollTop();
}

function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function showhide(id)
{
    if (document.getElementById)
    {
        obj = document.getElementById(id);
        if (obj.style.display == "none")
        {
            obj.style.display = "";
        }
        else 
        {    
            obj.style.display = "none";    
        }
    }
}
