function emit(Text)
{
	document.write(Text);
}

function emitln(Text)
{
	document.writeln(Text);
}

function element(i)
{
	if (document.getElementById)
		return document.getElementById(i);
	if (document.all)
		return document.all(i);
	if (document.layers)
		return document.layers(i);
}

function Refresh()
{
	document.location.href = document.location.href;
}

function Redirect(Url)
{
	document.location.href = Url;
}

function RedirectRoot()
{
	document.location.href = '/';
}

function ReplaceSubstring(inputString, fromString, toString)
{
	//return inputString.replace(fromString, toString);
	inputString = escape(inputString);
	fromString = escape(fromString);
	toString = escape(toString);
	
	// Goes through the inputString and replaces every occurrence of fromString with toString
	var temp = inputString;
	if (fromString == "")
		return unescape(inputString);

   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return unescape(temp); // Send the updated string back to the user
} // Ends the "replaceSubstring" function

/*function getCookie(name)
{
	var prefix = name + "=";
	var StartIndex = document.cookie.indexOf(prefix);
	if (StartIndex == -1)
		return null;
	var EndIndex = document.cookie.indexOf(";", StartIndex + prefix.length);
	if (EndIndex == -1)
		EndIndex = document.cookie.length;
	return unescape(document.cookie.substring(StartIndex + prefix.length, EndIndex));
}*/

function WriteLogOff()
{
	emit('<table title="Покинуть режим авторизованного пользователя"><tr><td valign=middle>');
	emit('<a href="/Admin/Logoff.aspx"><img src="/images/logout.gif" border=0></a> ');
	emit('</td><td valign=middle>');
	emit('<a class="CommandButton" href="/Admin/Logoff.aspx" style="width:100%;">Выйти</a>');
	emit('</td></tr></table>');
}

var BottomPanelHeight = 32;

function WindowResize()
{
	//SetPageTitle(' ' + /*document.body.clientHeight - */element('MainTableResizeAnchor').offsetTop);
	if (element('MainTableResize') != null)
		element('MainTableResize').height = document.body.clientHeight - element('MainTableResizeAnchor').offsetTop - BottomPanelHeight - 1;// - BottomPanelHeight;// - element('MainTableResize').OffsetTop;//BottomPanelHeight * 2;
		//element('MainTableResize').height = document.body.clientHeight - element('MainTableResizeAnchor').offsetTop;// - element('MainTableResize').OffsetTop;//BottomPanelHeight * 2;
}
window.onresize = WindowResize;
//document.body.onresize = WindowResize;
//element('body')['onresize'] = WindowResize;

function WriteResizeTable()
{
	emit('<table id="MainTableResizeAnchor" border="0" cellpadding="0" cellspacing="0" width="100%">');
	emit('<tr>');
		emit('<td id="MainTableResize" valign=top nowrap>');
}

function WriteResizeTableEnd()
{
		emit('</td>');
	emit('</tr>');
	emit('</table>');
	emit('<a id="MainTableResizeAnchor2"></a>');
}

function WriteHeader1()
{
	//emit('<div style="color:#000000; white-space:normal; position:relative;overflow: hidden; left:15; top:-21; float: bottom; margin: -14px; padding: -21px" nowrap>' + Text + '</div>');
	//emit('<div style="float:left; position:relative; left:16; top:-36">' + Text + '</div>');
	//emit('<div style="position:relative; left:16; top:-21">');
	//	emit('<span style="float: left; margin: -21px; left: 38; position:relative; z-index:0">');
	//emit('<div><a style="float: top;  margin: 0px; left: 0; position:absolute; z-index:0">');
	emit('<span style="text-indent: 0; margin-left: 16px; margin-top: 3px; float: left; position: absolute; z-index:0">');
	emit('<span class="Head">');
	//emit('<span class="Head" style="text-indent: 0; margin-left: 16px; margin-top: 3px; float: left; position: absolute; z-index:0">');
	//emit('<a class="Head" style="text-indent: 0; margin-left: 16px; margin-top: 3px; float: left; position: absolute; z-index:0">');
	//margin: 0; margin-left: 0px; margin-top: 1px;
}

function WriteHeader2()
{
	emit('</span>');
	emit('</span>');
	//box-sizing: content-box;
	//box-sizing: border-box;
	
	/*emit('<table cellspacing="0" cellpadding="0" border="0" width="100%">');
	emit('<tr>');
	emit('<td valign="middle" height="24" nowrap>');*/

	emit('<table cellspacing="0" cellpadding="0" border="0" width="100%">');
	emit('<tr height="24">');
	emit('<td width="16" background="/images/ui/hd_left.png" nowrap></td>');
	
	emit('<td background="/images/ui/hd_center.png" width="100%"></td>');
	emit('<td width="128" background="/images/ui/hd_gr.png" nowrap></td>');
	emit('</tr>');
	emit('</table>');


	/*emit('</td>');
	emit('</tr>');
	emit('</table>');*/
	//emit('<br>');
}

function WriteHeader(Text)
{
	WriteHeader1();
	emit(Text);
	WriteHeader2();
}

function WriteDesktopBottom()
{
	WindowResize();
	/*emit('<table border="0" cellpadding="0" cellspacing="0" width="100%"">');
	emit('<tr>');
		emit('<a id="MainTableResizeAnchor"></a>');
		emit('<td id="MainTableResize" valign=bottom height=128>');*/
			emit('<table border="0" cellpadding="0" cellspacing="0" width="100%" height="32">');
			emit('<tr>');
				emit('<td nowrap height="32" width="12" background="/images/ui/bottom_left.gif" nowrap></td>');
				emit('<td width="100%" height="32" class="copyright" valign="middle" background="/images/ui/bottom_center.gif">© 2004–2008 ЗАО «Строительно-инвестиционный холдинг «ЛИКОС». Все права защищены.</td>');
				emit('<td nowrap width="80" background="/images/ui/bottom_right.gif" nowrap><a href="#begin" onClick="scrollTo(0,0); return false;"><img width="80" height="28" alt="Наверх" title="Наверх" src="/images/1x1.gif" border="0"></a></td>');
			emit('</tr>');
			emit('</table>');
		/*emit('</td>');
	emit('</tr>');
	emit('</table>');*/
}

function WritePortals()
{
	emit('');
}

function WriteBorder()
{
	emit('<table cellpadding="1" cellspacing="1"><tr><td bgcolor="black">');
}

function WriteBorderEnd()
{
	emit('</td></tr></table>');
}

function WriteV_Line()
{
	emit('<td width=1 background="/images/ui/v_line.gif" nowrap></td>');
}

function WriteVSpacer(Height)
{
	emit('<table width="100%" height="' + Height + '" cellspacing="0" cellpadding="0" border="0">');
	emit('<tr><td nowrap></td></tr>');
	emit('</table>');
}

function WriteHSpacer(Width)
{
	emit('<table cellspacing="0" cellpadding="0" border="0">');
	emit('<tr><td nowrap width="' + Width + '" height="0"></td></tr>');
	emit('</table>');
}

// Ссылка "Наверх"
function WriteUp()
{
	emit('<a href="#begin"><b>Наверх</b></a>');
}

// Требуемое поле - красная звёздочка
function WriteRequiredField()
{
	emit('<font color="red">*</font>');
}

// Корзина
function StoreWriteCart()
{
	emit('<img src="/store/images/cart.gif" border=0 alt="Корзина"> Корзина');
}

// Купить
function StoreWriteBuy()
{
	emit('<img src="/store/images/buy.gif" border=0 alt="Купить">');
}

function StoreOpenWnd(url, target, param, wnd , default_param)
{
	var x, y;
	x = Math.round((screen.availWidth - 640) / 2);
	y = Math.round((screen.availHeight - 512) / 2);
	default_param = 'toolbar=0,status=1,scrollbars=1,resizable=1' +
		',left=' + x.toString() + 
		',top=' + y.toString();
	param = (param) ? ',' + param : '';
	param =  default_param + param
	wnd=open(url, target, param);
	wnd.focus();
	return wnd;
}

function StoreFloatWindow()
{
	StoreOpenWnd
	(
		'',
		'wfloat',
		'width=640,height=512,scrollbars=yes'
	);				
}


function EditorWriteTop()
{
	emit('<table border="0" cellpadding="0" cellspacing="0" width="100%" height="32" background="/images/ui/menu_center.gif">');
	emit('<tr>');
		//emit('<td width="12" background="/images/ui/bottom_left.gif" nowrap></td>');
		emit('<td width="12" nowrap></td>');
		emit('<td width="100%" class="NormalWhite" valign="middle"><b>Редактор</b></td>');
		//emit('<td width="80" background="/images/ui/bottom_right.gif" nowrap><a href="#begin"><img width="100%" height="100%" alt="Наверх" src="/images/1x1.gif" border="0"></a></td>');
	emit('</tr>');
	emit('</table>');
	
	emit('<table height="16" cellSpacing="0" cellPadding="0" width="100%" border="0" nowrap>');
	emit('<tr>');
		emit('<td background="/images/ui/logo_shadow.png" height="8"></td>');
	emit('</tr>');
	emit('<tr>');
		emit('<td height="8"></td>');
	emit('</tr>');
	emit('</table>');
}

function EditorWritePad()
{
	emit('<table border="0" cellpadding="0" cellspacing="0" width="100%">');
	emit('<tr><td class="EditorPad">');
}

function EditorWritePadEnd()
{
	emit('</td></tr>');
	emit('</table>');
}

// Опрос
function VoteWriteView()
{
	emit('<table border="0" cellpadding="0" cellspacing="0" width="100%">');
	emit('<tr><td style="padding-right: 8px; padding-left: 8px; text-indent: 0pt;">');	
}

function VoteWriteViewEnd()
{
	emit('</td></tr>');
	emit('</table>');
}

// Таблица результатов
function VoteResultTable()
{
	emit('<table cellpadding="4" cellspacing="0" style="border-collapse:collapse" bordercolor=black border=1>');
}

function VoteResultTableEnd()
{
	emit('</table>');
}

function VoteResultRow(Head, Title, Count, Percent, IsMax)
{
	emit('<tr ' + (Head ? 'style="background-color:navy;color:white"':(IsMax ? 'style="background-color:yellow;font-weight:bold"':'')) + '>');
		emit('<td width=240>' + Title + '</td>');
		emit('<td width=52 align=right>' + Count + '</td>');
		emit('<td width=52 align=right>' + Percent + '</td>');
		emit('<td width=100 align=center>');
		if (Head)
			emit('<b>Соотношение</b>');
		else
		{
			emit
			(
				'<table width=100 border=1 bordercolor=black style="border-collapse:collapse; background-color:#ccffcc" cellpadding="0" cellspacing="0">' +
					'<tr height=12>'
			);
			if (Percent > 0)
				emit
				(
						'<td style="background-color:green"  width=' + Percent + '></td>'
				);
				emit
				(
						'<td></td>' +
					'</tr>' +
				'</table>'				
				);
		}
		emit('</td>');
	emit('</tr>');
}

// Альтернативная страница
// Шапка
function PagesTop()
{
	emit('<table border="0" cellpadding="0" cellspacing="0" width="100%" height="32" background="/images/ui/menu_center.gif">');
	emit('<tr>');
		//emit('<td width="12" background="/images/ui/bottom_left.gif" nowrap></td>');
		emit('<td width="12" nowrap></td>');
		emit('<td width="100%" class="NormalWhite" valign="middle"><b>' + document.title + '</b></td>');
		//emit('<td width="80" background="/images/ui/bottom_right.gif" nowrap><a href="#begin"><img width="100%" height="100%" alt="Наверх" src="/images/1x1.gif" border="0"></a></td>');
	emit('</tr>');
	emit('</table>');
	
	emit('<table height="16" cellSpacing="0" cellPadding="0" width="100%" border="0" nowrap>');
	emit('<tr>');
		emit('<td background="/images/ui/logo_shadow.png" height="8"></td>');
	emit('</tr>');
	emit('<tr>');
		emit('<td height="8"></td>');
	emit('</tr>');
	emit('</table>');
}

// Низ левой части
function PagesLeftBarBottom()
{
	emit
	(
		'<img src="/images/ui/left_city.gif">'
	);
}

// Низ правой части
function PagesRightBarBottom()
{
	emit
	(		
		'<img src="/images/ui/right_city.gif">'
	);
}

// Низ
function PagesBottom()
{
	WriteDesktopBottom();
}

function PagesBody()
{
	emit('<table border="0" cellpadding="0" cellspacing="0" width="100%">');
	emit('<tr><td style="padding-right: 16px; padding-left: 16px; text-indent: 0pt;">');	
}

function PagesBodyEnd()
{
	emit('</td></tr>');
	emit('</table>');
}