function pad(number)
{
	return (number < 10)? '0' + number: number;
}

function hideFlat(id)
{
	var objImg = document.getElementById('flat'+id);
	objImg.style.visibility = 'hidden';
	var objDiv = document.getElementById('ftext'+id);
	objDiv.style.visibility = 'hidden';
}

function hideAllFlats(id)
{
	for (i=1; i<=11; i++)
	{
		hideFlat(pad(i));		
	}
}

function showFlat(id)
{
	hideAllFlats();
	var objImg = document.getElementById('flat'+id);
	objImg.style.visibility = 'visible';
	var objDiv = document.getElementById('ftext'+id);
	objDiv.style.visibility = 'visible';
}


function popup(url,width,height,scroll)
{
  window.open('/'+url,'popup','width='+width+',height='+height+',status=no,toolbar=no,menubar=no,scrollbars='+scroll+',resizable=no');
}

function popWindow(url,width,height)
{
	myWin = window.open('/','popup','width='+(parseInt(width)+20)+',height='+(parseInt(height)+40)+',status=no,toolbar=no,menubar=no,scrollbars=no,resizable=no');
	var tmp = myWin.document;
	tmp.write('<html><head><title>«Импера»</title><meta http-equiv=Content-Type content="text/html; charset=windows-1251">');
	tmp.write('<style type=text/css>a {font-family:Tahoma,Arial,sans-serif;font-size:11px; color:blue} a:hover {color:fe8d56} </style>');
	tmp.write('</head><body topmargin=10 leftmargin=10 marginheight=10 marginwidth=10><img src=/'+url+' width='+width+' height='+height+'>');
	tmp.write('<div style="text-align:center; margin-top:5px"><a href="javascript:self.close()">Закрыть окно</a></div>');
	tmp.write('</body></html>');
	tmp.close();
}

function confirmDel(url) 
{
  if(confirm('Вы действительно хотите это сделать?'))
  {
    window.location.href = url;
	return(true);
  }
}

function getRadioValue(RadioName)
{
  var colRadio = document.getElementsByName(RadioName);
  for (var i = 0; i < colRadio.length; i++)
  {
    if (colRadio[i].checked)
    {
      return colRadio[i].value;
    }
  }
  return null;
}

function toggle(what)
{
  if(document.getElementById)
  {
    newState = (document.getElementById(what).style.display == 'none')? 'block': 'none';
    document.getElementById(what).style.display = newState;
  }
}

function showPic(whichpic)
{
	if(document.getElementById)
	{
		for(var x=0; document.getElementById('filmstrip').childNodes[x]; x++)
		{
			if(document.getElementById('filmstrip').childNodes[x].tagName == 'A')
			{
			  document.getElementById('filmstrip').childNodes[x].childNodes[0].className = 'galleryImage';
			}
		}
		whichpic.childNodes[0].className = 'galleryImageActive';

		document.getElementById('placeholder').src = whichpic.href;
		
		document.getElementById('desc').childNodes[0].nodeValue = whichpic.title;
    document.getElementById('desc').className = (whichpic.title == '')? 'no-display': 'display';

		return false;
	}
	else
	{
		return true;
	}
}

function showPlan(whichpic)
{
	if(document.getElementById)
	{

		document.getElementById('placeholder').src = whichpic.href;



		document.getElementById('desc').childNodes[0].nodeValue = whichpic.title;
    document.getElementById('desc').className = (whichpic.title == '')? 'no-display': 'display';

		for(var x=0; document.getElementById('numberStrip').childNodes[x]; x++)
		{
			if(document.getElementById('numberStrip').childNodes[x].tagName == 'A')
			{
			  document.getElementById('numberStrip').childNodes[x].childNodes[0].className = 'number';
			}
		}
		whichpic.childNodes[0].className = 'numberActive';

		

		return false;
	}
	else
	{
		return true;
	}
}

function getDragParent(el) {
	var oldEl=el;
	while (el) {
		el=el.parentNode;
		if (el.id=="maptable" || el.nodeName.toUpperCase()=='BODY') {
			return oldEl;
		}
		oldEl=el;
	}
}

var offsetX,offsetY,draggingThing;
function startDrag(e) {
	draggingThing=getDragParent(e.srcElement || e.target); 
	offsetX=e.clientX-draggingThing.offsetLeft;
	offsetY=e.clientY-draggingThing.offsetTop;
	document.body.onmousemove=moveDrag;
	document.body.onmouseup=endDrag;
	document.onselectstart=nullFunc;
}

function nullFunc(e) {
	return false;
}
function moveDrag(e) {
	e=e || event;
	if (draggingThing) {
		draggingThing.style.top=(e.clientY-offsetY)+'px';
		draggingThing.style.left=(e.clientX-offsetX)+'px';
		return true;
	}
}
function endDrag(e) {
	draggingThing=null;
	document.body.onmousemove=null;
	document.body.onmouseend=null;
	document.onselectstart=null;
}

