var contentObj = null;
var conObj = null;
var screenObj = null;
var selects_elms = null;

function HideSelects()
{
 selects_elms = document.getElementsByTagName('select');
 for (var i = 0; i < selects_elms.length; i++)
 {
 selects_elms[i].style.visibility = 'hidden';
 }
}

function ShowSelects()
{
 if (selects_elms != null)
 {
 for (var i = 0; i < selects_elms.length; i++)
 {
 selects_elms[i].style.visibility = 'visible';
 }
 }
}

function modalPrepare()
{
 if (window.ie6)
 {
 HideSelects();
 }
 contentObj = $('overall_modal');
 screenObj = $('overall_screen');
 contentObj.style.display = 'block';
 screenObj.style.display = 'block';
 contentObj.style.width = '640px';
 if (window.getHeight() > 1000) to = 298
 else if (window.getHeight() > 800) to = 199
 else to = 148;
 if (t = window.getScrollTop()) contentObj.style.top = (t + to) + 'px';
 else contentObj.style.top = to + 'px';
 screenObj.style.height = getyScroll() + 'px';

 print_link = $('print_file_css');
 print_link.href = pathRoot + '_css/print_popup.css';
}

function modalPost(url, query, form)
{
 if (form)
 {
 var form_id = form.id;
 var form_query = $(form_id).toQueryString();
 }
 modalPrepare();
 if (contentObj != null)
 {
 contentObj.innerHTML = '<div class="pop-askqu"><center><img src="' + pathRoot + '_img/ajax-loader.gif" width="50" height="50" /></center></div>';
 var xhrReq = new XHR({method: 'post', encoding: 'windows-1251', onSuccess: function(req) { modalRequest(req); }});
 if (query != '')
 {
 query += '&';
 }
 if (form_query)
 {
 query += form_query;
 }
 xhrReq.send(url, query);
 }
}

function modalGet(url, query)
{
 modalPrepare();
 if (contentObj != null)
 {
 contentObj.innerHTML = '<div class="pop-askqu"><center><img src="' + pathRoot + '_img/ajax-loader.gif" width="50" height="50" /></center></div>';
 var xhrGReq = new XHR({method: 'get', encoding: 'windows-1251', onSuccess: function(req) { modalRequest(req); }});
 xhrGReq.send(url, query);
 }
}

function justGet(url, objId, newClass)
{
 conObj = $(objId);
 if (conObj != null)
 {
 var hObj = $('the-headerest');
 var hdr = '<h1 id="the-headerest">' + hObj.innerHTML + '</h1>';
 stabHeight = conObj.getSize().size.y;
 conObj.style.height = (stabHeight - 57) + 'px';
 $('forest').className = newClass;
 conObj.innerHTML = hdr + '<center><img src="' + pathRoot + '_img/ajax-loader.gif" width="50" height="50" /></center>';
 var xhrR = new XHR({method: 'get', encoding: 'windows-1251', onSuccess: function(req) { justRequest(req, hdr); }});
 xhrR.send(url);
 }
}

function screenObjRresize()
{
 screenObj.style.height = getyScroll() + 'px';
}

function modalRequest(req)
{
 contentObj.innerHTML = req;
 setTimeout('screenObjRresize()', 1000);
}

function justRequest(req, hdr)
{
 conObj.innerHTML = hdr + req;
 conObj.style.height = '';
 var wTitleObj = $('hidden-title');
 var docTitle = 'Ондулин';
 if (wTitleObj && wTitleObj.innerHTML != '')
 {
 docTitle += ' — ' + wTitleObj.innerHTML;
 }
 document.title = docTitle;
}

function getyScroll()
{
 yScroll = 0;
 if (window.innerHeight && window.scrollMaxY)
 {
 yScroll = window.innerHeight + window.scrollMaxY;
 var deff = document.documentElement;
 var hff = (deff&&deff.clientHeight) || document.body.clientHeight || window.innerHeight || self.innerHeight;
 yScroll -= (window.innerHeight - hff);
 }
 else if (document.documentElement.scrollHeight > document.body.offsetHeight)
 {
 yScroll = document.documentElement.scrollHeight;
 }
 else
 {
 yScroll = document.body.offsetHeight;
 }
 return yScroll;
}

function modalClose()
{
 if (window.ie6)
 {
 ShowSelects();
 }
 if (contentObj != null)
 {
 contentObj.innerHTML = '';
 contentObj.style.display = 'none';
 contentObj = null;
 screenObj.style.display = 'none';
 screenObj = null;
 }
}
