function get_page_size(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array($(document.body).getWidth(),pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}


function get_page_scroll(){

	var yScroll = self.pageYOffset || document.documentElement.scrollTop;

	return yScroll;
}


function reload_content(div, url, fund_id, type, from, to)
{
//	if(from != '' && to != ''){
		new Ajax.Request(url, {
		  method: 'post',
		  parameters : "?fund_id=" + fund_id + "&from=" + from + "&to=" + to + "&reload=" + type,

		  onSuccess: function(transport) {
			$(div).update(transport.responseText);

			if(!transport.responseText)
			{
				$$('.' + div + '.save_excel')[0].hide();
			}
			else
			{
				$$('.' + div + '.save_excel')[0].show();
			}

			TableKit.Sortable.init($$('#' + div + ' table.sortable')[0]);

			$('footer').setStyle({'bottom' : '0'});
		  }
		});
//	}
}

function reload_chart(url)
{
	if($('gfx_from').value != '' && $('gfx_to').value && $('gfx_from').value < $('gfx_to').value)
	{
		new Ajax.Request(url, {
		  method: 'post',
		  parameters : "&from=" + $('gfx_from').value + "&to=" + $('gfx_to').value,

		  onSuccess: function(transport) {
			$('flash_chart').update(transport.responseText);
		  }
		});
	}
}

function calculate(url, day_1, day_2)
{
	if(day_1 != '' && day_2 != '')
	{
		new Ajax.Request(url, {
		  method: 'post',
		  parameters : "&day_1=" + day_1 + "&day_2=" + day_2,

		  onSuccess: function(transport) {
			$('calc_result').update(transport.responseText);
		  }
		});
	}
}


function disallowDate(date)
{
	var cur_date_obj = new Date();
	/*
	var cur_month = cur_date_obj.getMonth() < 10 ? '0'+(cur_date_obj.getMonth()).toString() : cur_date_obj.getMonth();
	var cur_day = cur_date_obj.getDate() < 10 ? '0'+(cur_date_obj.getDate()).toString() : cur_date_obj.getDate();
	var cur_date = parseInt((cur_date_obj.getFullYear()).toString() + cur_month + cur_day);

	var showed_month = date.getMonth() < 10 ? '0'+(date.getMonth()).toString() : date.getMonth();
	var showed_day = date.getDate() < 10 ? '0'+(date.getDate()).toString() : date.getDate();
	var showed_date = parseInt((date.getFullYear()).toString() + showed_month + showed_day);

	// date is a JS Date object
	if (showed_date >= cur_date || date.getDay() == 0 || date.getDay() == 6) {
		return true; // disable July 5 2003
	}*/
	if (date >= cur_date_obj || date.getDay() == 0 || date.getDay() == 6 || (cur_date_obj.getFullYear() == date.getFullYear() && cur_date_obj.getMonth() == date.getMonth() && cur_date_obj.getDate() == date.getDate())) {
		return true; // disable July 5 2003
	}

	return false; // enable other dates
};


Event.observe(window, 'load', function(){
	var buttons = $$('button[type=button]');
	if(buttons.length)
	{
		for(i = 0; i < buttons.length; i++)
        {
			if(buttons[i].form
			   && (btn_id=buttons[i].id.toString())
			   && btn_id.indexOf('btn_') == 0
			   && (inp=buttons[i].form[btn_id.replace(/^btn_/, '')]))
			{
				if($(inp).hasClassName('date_input')) {
					Calendar.setup({inputField:inp.id, button: btn_id, disableFunc: disallowDate});
				}
			}
        }
	}

	TableKit.options.rowOddClass = 'blue';
	TableKit.options.rowEvenClass = '';

	//LOAD FLASH CHART
//	var scripttag = document.getElementsByTagName('script')[0];
//	wwwbase = (scripttag.src.match(/(.*)public\/js.*/)[1]) + 'flash/prices';

	new Ajax.Request(url, {
		method: 'post',
		//parameters: 'show=' + p_show + '&days=' + p_days + '&index=' + ind + '&percent=' + percent,
		onSuccess: function(transport) {
			$('flash_chart').update(transport.responseText);
		}
	});

});
