
function getPageSizeWithScroll()
{
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
	return arrayPageSizeWithScroll;
}

function CheckFormData()
{

	var text = document.send_form.newtext.value;
	
	if(text.length < 10)
	{
		alert("Введите текст комментария");
		return false;
	}

	return true;

}

function show_comment_form(id, parent)
{

	var body = document.body;
	
	var screen_width = 0;
	if(document.documentElement.clientWidth)
	{
		screen_width = document.documentElement.clientWidth - 4;
	}
	else
	{
		screen_width = document.body.offsetWidth - 20;
	}
	
	var screen_height = 0;
	if(document.documentElement.clientHeight)
	{
		screen_height = document.documentElement.clientHeight + 4;
	}
	else
	{
		var sizes = getPageSizeWithScroll();
		screen_height = sizes[1];	
	}
	
	var body_height = body.offsetHeight;
	var scroll = body.scrollTop ? body.scrollTop : document.documentElement.scrollTop;

	
	var layer = document.getElementById('comment');
	if(layer)
	{	
	
		document.comment_form.parent.value = parent;		
	
		var width = layer.offsetWidth;
		var height = layer.offsetHeight;
		
		layer.style.top = scroll + 'px';
		
		if(width < screen_width)
		{
			var offset = (screen_width - width) / 2;
			layer.style.left = offset + 'px';
		}
		
		if(height < screen_height)
		{
			var offset = (screen_height - height) / 2;
			layer.style.top = (scroll + offset) + 'px';
		}	
		
		layer.style.visibility = 'visible';
		layer.style.zIndex = '999';
		
	}
	
	
}


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 { // 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(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function show_form(form_name)
{

	//alert(form_name);
	var body = document.body;
	
	var screen_width = 0;
	if(document.documentElement.clientWidth)
	{
		screen_width = document.documentElement.clientWidth - 4;
	}
	else
	{
		screen_width = document.body.offsetWidth - 20;
	}
	
	var screen_height = 0;
	if(document.documentElement.clientHeight)
	{
		screen_height = document.documentElement.clientHeight + 4;
	}
	else
	{
		var sizes = getPageSizeWithScroll();
		screen_height = sizes[1];	
	}
	
	var body_height = body.offsetHeight;
	var scroll = body.scrollTop ? body.scrollTop : document.documentElement.scrollTop;
	
	
	var layer = document.getElementById(form_name);
	if(layer)
	{		
	
		var width = layer.offsetWidth;
		var height = layer.offsetHeight;
		
		layer.style.top = scroll + 'px';
		
		if(width < screen_width)
		{
			var offset = (screen_width - width) / 2;
			layer.style.left = offset + 'px';
		}
		
		if(height < screen_height)
		{
			var offset = (screen_height - height) / 2;
			layer.style.top = (scroll + offset) + 'px';
		}	
		
		layer.style.visibility = 'visible';
		layer.style.zIndex = '999';
		
	}
			
}

function hide_form(form_name)
{

	var layer = document.getElementById(form_name);
	if(layer)
	{
		layer.style.visibility = 'hidden';		
	}
	
	var bglayer = document.getElementById('bglayer');
	if(bglayer)
	{
		bglayer.parentNode.removeChild(bglayer);
	}
	
}

function open_photos(userid)
{
	
	var photos_popup = window.open('photos_popup.php?id='+userid, 'photos', 'width=700,height=700');

}

function show_present(elem, author, text, date)
{

	var bounds = getBounds(elem);
	
	var body = document.body;
	
	var screen_width = 0;
	if(document.documentElement.clientWidth)
	{
		screen_width = document.documentElement.clientWidth - 4;
	}
	else
	{
		screen_width = document.body.offsetWidth - 20;
	}
	
	var screen_height = 0;
	if(document.documentElement.clientHeight)
	{
		screen_height = document.documentElement.clientHeight + 4;
	}
	else
	{
		var sizes = getPageSizeWithScroll();
		screen_height = sizes[1];	
	}
	//alert(screen_height);
	
	var body_height = body.offsetHeight;
	var scroll = body.scrollTop ? body.scrollTop : document.documentElement.scrollTop;

	
	var layer = document.getElementById('present_comment');
	if(layer)
	{	
		var width = layer.offsetWidth;
		var height = layer.offsetHeight;
		
		layer.style.left = (bounds.left - 85) + 'px';
		//layer.style.top = (bounds.top + scroll + 100) + 'px';
		layer.style.top = (bounds.top + 100) + 'px';
				
		layer.style.visibility = 'visible';
		layer.style.zIndex = '999';
		
		
		var present_author_date = document.getElementById('present_author_date');
		if(present_author_date)
		{
			present_author_date.innerHTML = '<span style="color: red;">' + author + '</span>';
		 	//present_author_date.innerHTML = author + ' ' + date;
		}
		
		var present_text = document.getElementById('present_text');
		if(present_text)
		 	present_text.innerHTML = text;
	}
}

function getBounds(element)
{
  var left = element.offsetLeft;
  var top = element.offsetTop;
  for (var parent = element.offsetParent; parent; parent = parent.offsetParent)
  {
    left += parent.offsetLeft - parent.scrollLeft;
    top += parent.offsetTop - parent.scrollTop
  }
  return {left: left, top: top, width: element.offsetWidth, height: element.offsetHeight};
}

function show_tip(elem, text)
{

	var bounds = getBounds(elem);
		

	var body = document.body;
	
	var screen_width = 0;
	if(document.documentElement.clientWidth)
	{
		screen_width = document.documentElement.clientWidth - 4;
	}
	else
	{
		screen_width = document.body.offsetWidth - 20;
	}
	
	var screen_height = 0;
	if(document.documentElement.clientHeight)
	{
		screen_height = document.documentElement.clientHeight + 4;
	}
	else
	{
		var sizes = getPageSizeWithScroll();
		screen_height = sizes[1];	
	}
	
	var body_height = body.offsetHeight;
	var scroll = body.scrollTop ? body.scrollTop : document.documentElement.scrollTop;


	var tiptext = document.getElementById('tip_text');
	if(tiptext)
	{
		tiptext.innerHTML = text;		
	}
	
	
	var tip = document.getElementById('tip');
	if(tip)
	{	
	
		tip.style.width = '400px';
		tip.style.height = '150px';
		
		var width = tip.offsetWidth;
		//var width = tip.style.width;
		var height = tip.offsetHeight;
		//alert(width);
		
		tip.style.left = (bounds.left + 25) + 'px';
		tip.style.top = (bounds.top + scroll - height/2) + 'px';
		//tip.style.width = '810px';
		tip.style.zIndex = 999;
		tip.style.visibility = 'visible';
				
	}
	
}

function hide_tip()
{

	var tip = document.getElementById('tip');
	if(tip)
	{
		tip.style.visibility = 'hidden';		
	}
	
	var tiptext = document.getElementById('tip_text');
	if(tiptext)
	{
		tiptext.innerHTML = '';		
	}

}


document.getElementsByClassName = function(cl) {
var retnode = [];
var myclass = new RegExp('\\b'+cl+'\\b');
var elem = this.getElementsByTagName('*');
for (var i=0; i<elem.length; i++) {
var classes = elem[i].className;
if (myclass.test(classes)) retnode.push(elem[i]);
}
return retnode;
}

sfHover = function() {
	//var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	var sfEls = document.getElementsByClassName("pic_top");
	//alert(sfEls.length);
	
	/*
	document.getElementById('browser').getAttribute('name');
	
	if(name == "ie") {
	
	for (var i=0;i<sfEls.length;i++) {
		sfEls[i].onmouseover=function() {
			this.className = "pic_top_over";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp("pic_top_over\\b"), "pic_top");
		}
	}
	
	}
	*/
	
}

if (window.attachEvent) window.attachEvent("onload", sfHover);


function Add()
		{
		
			while(document.search.city.options.length > 0)
				document.search.city.options[document.search.city.options.length - 1] = null;
			
			document.search.city.options[0] = new Option('Не выбран', '');
			
			var country = document.search.country.options[document.search.country.selectedIndex].value;
			for(var i=0; i<cities[country].length; i++)
			{
				document.search.city.options[document.search.city.options.length] = new Option(cities[country][i], cities[country][i]);
			}
			
		}
