function getPageSize() {
	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 if (document.documentElement && document.documentElement.scrollHeight > document.documentElement.offsetHeight) { // Explorer 6 strict mode
		xScroll = document.documentElement.scrollWidth;
		yScroll = document.documentElement.scrollHeight;
	} else { // Explorer Mac...would also work in 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;
	}
	//alert('xScroll: ' + xScroll + '\n' + 'yScroll: ' + yScroll + '\n' + 'pageWidth: ' + pageWidth + '\n' + 'pageHeight: ' + pageHeight + '\n' + 'windowWidth: ' + windowWidth + '\n' + 'windowHeight: ' + windowHeight + '\n');
	arrayPageSize = new Array(xScroll, yScroll, pageWidth, pageHeight, windowWidth, windowHeight)
	return arrayPageSize;
}

function show_popup_login() {
	var obj = document.getElementById('login_box');
	var page_size = getPageSize();
	var popup_width = 382;
	var site_width = 935;
	
	right_pos = (page_size[0] - site_width) / 2 - 14;
	
	obj.style.right = right_pos + 'px';
	obj.style.display = 'block';
	document.getElementById('popup_username').focus();
}

function hide_popup_login() {
	var obj = document.getElementById('login_box');
	obj.style.display = 'none';
}

function validate_popup_login() {
	if(document.getElementById('popup_username').value.length == 0) {
		alert('Моля, въведете потребителско име или email!');
		document.getElementById('popup_username').focus();
		return (false);
	}

	if(document.getElementById('popup_password').value.length == 0) {
		alert('Моля, въведете парола!');
		document.getElementById('popup_password').focus();
		return (false);
	}
	
	return true;
}

function show_hide(ele, ele1, ele2) {
	var x, y, z;
	
	if ( document.getElementById && (x = document.getElementById(ele))&& x.style ) {
		x.style.display = ('none' == x.style.display)? '' : 'none' ;
	}
	
	if ( document.getElementById && (y = document.getElementById(ele1)) && y.style ) {
		y.style.display = ('none' == y.style.display)? '' : 'none' ;
	}
	
	if ( document.getElementById && (z = document.getElementById(ele2)) && z.style ) {
		z.style.display = ('none' == z.style.display)? '' : 'none' ;
	}
}










var popup_xmlhttp;
var popup_respond  = 'login_box';
var popup_callback = popup_callback;

function popup_ajax_login() {
	popup_xmlhttp = popup_GetXmlHttpObject();
	if(popup_xmlhttp == null) {
		alert ("Your browser does not support AJAX!");
		return;
	}
	
	popup_respond  = 'login_box';
	var username = document.getElementById('popup_username').value;
	var password = document.getElementById('popup_password').value;
	
	var url="/ajax/ajax_popup_login.php";
	url = url + "?username=" + username;
	url = url + "&password=" + password;
	
	popup_xmlhttp.onreadystatechange = popup_stateChanged;
	popup_xmlhttp.open("GET", url, true);
	popup_xmlhttp.send(null);
}

function popup_stateChanged() {
	if (popup_xmlhttp.readyState == 4) {
		document.getElementById(popup_respond).innerHTML = popup_xmlhttp.responseText;
		
		var do_reload = document.getElementById('do_reload');
		if(do_reload && do_reload.value == 1) location.reload(true);
		
		var do_redirect = document.getElementById('do_redirect');
		if(do_redirect && do_redirect.value != '') window.location.href = do_redirect.value;
		
		if(popup_callback != '') eval(popup_callback);
	}
}

function popup_GetXmlHttpObject() {
	if (window.XMLHttpRequest) {
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject) {
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}


















