function getCookieVal (offset)
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) {
		endstr = document.cookie.length;
	}
	return unescape(document.cookie.substring(offset, endstr));
}

function FixCookieDate (date)
{
	var base = new Date(0);
	var skew = base.getTime(); // dawn of (Unix) time - should be 0
	if (skew > 0) {  // Except on the Mac - ahead of its time
		date.setTime (date.getTime() - skew);
	}
}

function GetCookie (name)
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) {
			return getCookieVal (j);
		}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) {
			break;
		}
	}
	return null;
}

function SetCookie (name,value,expires,path,domain,secure)
{
	document.cookie = name + "=" + escape (value) +
            ((expires) ? "; expires=" + expires.toGMTString() : "") +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            ((secure) ? "; secure" : "");
}

function DeleteCookie (name,path,domain)
{
	if (GetCookie(name)) {
		document.cookie = name + "=" +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

function setc()
{
	var expdate = new Date ();
	FixCookieDate (expdate);
	expdate.setTime (expdate.getTime() + ((24 * 60 * 60 * 1000) * 30));
	SetCookie ("patchtest", "TEST", expdate);

}

function SaveC()
{
	var temp = "";
	for (var i = 0; i < document.check['ch[]'].length; i++)
	{
		if (document.check['ch[]'][i].checked)
		{
			temp +=	document.check['ch[]'][i].value + ",";
		}
	}
	//alert(temp);
	var expdate = new Date ();
	FixCookieDate (expdate);
	expdate.setTime (expdate.getTime() + ((24 * 60 * 60 * 1000) * 90));
	SetCookie ("currency", temp, expdate);
    GetTable();
	HideModalbox();
}

function GetTable() {
	document.getElementById('bodcu').style.display = 'none';
	document.getElementById('zag').style.display = '';
    var req = new JsHttpRequest();
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
        	document.getElementById('zag').style.display = 'none';
        	document.getElementById('bodcu').innerHTML = req.responseJS.resret;
        	document.getElementById('bodcu').style.display = '';
        }
    }
    req.open('GET', 'ind.php', true);
    req.send( { get: 'table' } );
}

function OpenWindow(url, title, x, y) {
	var left = parseInt((screen.availWidth/2) - (x/2));
    var top = parseInt((screen.availHeight/2) - (y/2));
	window.open (url, title, "toolbar=0, location=0, directories=0, status=0, scrollbars=1, resizable=0, copyhistory=0, width="+x+", height="+y+", left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top + "");
}

//------------------------------------------------------------------------------

var modalbox;
var shade;
var scrollWidth;
var scrollHeight;

window.onload = function()
{
	modalbox = document.getElementById("modalbox");
	shade = document.getElementById("shade");

	scrollWidth = document.body.scrollWidth;
	scrollHeight = document.body.scrollHeight;

	document.getElementById("main").style.width = scrollWidth;
	document.getElementById("main").style.height = scrollHeight;
}

function ShowModalbox()
{
	document.getElementById("main").style.filter = "alpha(opacity=80)";
	document.getElementById("main").style.opacity = 0.8;
	document.getElementById("main").style.display = "block";
	//document.getElementById("main").style.backgroundColor = "#68696B";

	modalbox.style.display = "block";
	shade.style.display = "block";

 	posleft = Math.round(f_clientWidth()/2) - 300;
 	//alert(posleft);
 	postop = f_scrollTop() + Math.round(f_clientHeight()/2);

 	//alert(f_scrollTop() + Math.round(f_clientHeight()/2));

	shade.style.left = posleft + 7;
	shade.style.top = postop + 7;

	modalbox.style.left = posleft;
	modalbox.style.top = postop;

	//setTimeout(HideModalbox, 5000)

}


function HideModalbox()
{
	document.getElementById("main").style.display = "none";
	modalbox.style.display = "none";
	shade.style.display = "none";
}

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 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
	);
}