﻿function getPageDimensions() {
	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, notIE = 0;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
		notIE = 1;
	} 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(windowWidth, windowHeight, pageWidth, pageHeight, notIE);
	return arrayPageSize;
}

function show_hide_twitters(showing, hiding) {
	var counter = 1;
	
	while(x = document.getElementById('twitter_' + counter)) {
		x.style.display = (x.style.display == "none") ? "block" : "none";
		counter++;
	}
	
	var y = document.getElementById('show_hide_twitters');
	var show_hide=document.getElementById('switch_show_hide').value;
	//alert(show_hide);
	if(show_hide>0)
	{
		document.getElementById('switch_show_hide').value=0;
		y.innerHTML = showing;
	}
	else
	{
		document.getElementById('switch_show_hide').value=1;
		y.innerHTML = hiding;
	}
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function show_login_box(object, page_name) {
	var coords = findPos(object);
	var x = coords[0];
	var y = coords[1];
	var obj = document.getElementById('login_box');
	//alert('x: ' + x + ' y: ' + y);
	
	if(page_name == 'overview' || page_name == 'financial-reports') {
		obj = document.getElementById('login_box_2');
		obj.style.left = x - 200 + 'px';
		obj.style.top = y - 240 + 'px';
	}
	else {
		obj.style.left = x - 212 + 'px';
		obj.style.top = y+400 + 'px';
	}
	
	obj.style.display = 'block';
}

function show_login_box2(object, page_name) {
	var coords = findPos(object);
	var x = coords[0];
	var y = coords[1];
	var obj = document.getElementById('login_box3');
	
	if(page_name == 'overview' || page_name == 'financial-reports') {
		obj = document.getElementById('login_box_3');
		obj.style.left = x - 200 + 'px';
		obj.style.top = y + 40 + 'px';
	}
	else {
		obj.style.left = x - 212 + 'px';
		obj.style.top = y + 'px';
	}
	
	obj.style.display = 'block';
}

function hide_login_box(num) {
	var obj = document.getElementById('login_box');
	if(num) obj = document.getElementById('login_box_' + num);
	obj.style.display = 'none';
}

function sub_string(srch, string) {
	var match_pos = string.search(srch);
	
	if(match_pos != -1) {
		//matched
		return true;
	}
	else {
		//not matched
		return false;
	}
}

function swap_checked(obj) {
	var str = 'unchecked';
	var my_string = obj.src;
	var match_pos = my_string.search(str);
	
	if(match_pos != -1) {
		//matched
		obj.src = my_string.replace(str, 'checked');
		show_column_by_class_name(obj.id);
		//alert('show ' + obj.id);
	}
	else {
		//not matched
		obj.src = my_string.replace('checked', str);
		hide_column_by_class_name(obj.id)
		//alert('hide ' + obj.id);
	}
}

function hide_column_by_class_name(cls_name) {
	var td_arr = document.getElementsByTagName('td');
	for(i=0; i<td_arr.length; i++) {
		if(sub_string(cls_name, td_arr[i].className)) {
			td_arr[i].style.display = 'none';
		}
	}
	init_dw_Scroll();
}

function show_column_by_class_name(cls_name) {
	var browser = BrowserDetect.init();
	var td_arr = document.getElementsByTagName('td');
	for(i=0; i<td_arr.length; i++) {
		if(sub_string(cls_name, td_arr[i].className)) {
			td_arr[i].style.display = (browser == 'Explorer') ? 'block' : 'table-cell'; // <-- OK
			//td_arr[i].style.display = 'table';
		}
	}
	init_dw_Scroll();
}

function fix_scrollbar_in_opera() {
	var browser = BrowserDetect.init();
	if(browser == 'Opera') {
		var x;
		if(x = document.getElementById('dragBar')) {
			x.style.backgroundPosition = '0 -1px';
		}
		if(x = document.getElementById('dragBarRight')) {
			x.style.backgroundPosition = '0 -1px';
		}
		if(x = document.getElementById('hide_corners')) {
			x.style.top = '0';
		}
	}
}

function fix_scrollbar_height2(a) {
	var x = document.getElementById(a);
	var z= document.getElementById('left_content');
	var y = document.getElementById('wn');
	//alert(x.offsetHeight);
	if(z.offsetHeight>x.offsetHeight)
	{
		y.style.height = z.offsetHeight + 'px';
	}
	else
	{
		y.style.height = x.offsetHeight + 'px';
	}
	fix_scrollbar_in_opera();
}

function fix_scrollbar_height() {
	var x = document.getElementById('left_content');
	var y = document.getElementById('wn');
	y.style.height = x.offsetHeight + 'px';
	
	fix_scrollbar_in_opera();
}


function show_desc(object, num, id) {
	var coords = findPos(object);
	var x = coords[0];
	var y = coords[1];

	var var_name = 'desc_' + num;
	document.getElementById('desc_content').innerHTML = eval(var_name);
	
	var obj;
	if(id) {
		obj = document.getElementById('desc_box_' + id);
		obj.style.left = x + 50 + 'px';
		obj.style.top = y - 20 + 'px';
	}
	else {
		obj = document.getElementById('desc_box');
		obj.style.left = x + 'px';
		obj.style.top = y + 10 + 'px';
	}
	
	obj.style.display = 'block';
}

function hide_desc(id) {
	if(id) {
		document.getElementById('desc_box_' + id).style.display = 'none';
	}
	else {
		document.getElementById('desc_box').style.display = 'none';
	}
	clearTimeout();
}

function fix_static_active() {
	var isMSIE = /*@cc_on!@*/false; //tova kazva dali browser-a e explorer
	var obj = document.getElementById('right_content');
	var parent = obj.parentNode;
	var coords = findPos(parent);
	var x = coords[0];
	var y = coords[1];
	//alert('x: ' + x + '\ny: ' + y);
	
	obj.style.top = y + 'px';
	obj.style.left = x + (parent.offsetWidth - obj.offsetWidth)/2 + 'px';
}










