var cat_PopupIFrame;

function catOpenModal(id)
{
	$("#" + id).css("display", "");
	var obj = $("#" + id)[0];
	if (obj) {
		var scrollTop = 0;
		if (window.pageYOffset) {  
			scrollTop = window.pageYOffset
		} else if(document.documentElement && document.documentElement.scrollTop) { 
			scrollTop = document.documentElement.scrollTop; 
		} else if(document.body) { 
			scrollTop = document.body.scrollTop; 
		}

		if (document.body.clientWidth <= 550) {
			obj.style.top = scrollTop + 130 + "px";
		} else {
			obj.style.top = scrollTop + 250 + "px";
		}
	}

	catCreateIframe(id);
}

function catCloseModal(id)
{
	$("#" + id).css("display", "none");
	catDeleteIframe(id);
}

function catCreateIframe(id)
{
	var obj_id = id;
	var iFrame = document.createElement("IFRAME");
	iFrame.setAttribute("src", "");
	//Match IFrame position with divPopup
	$("#" + obj_id)[0].style.display = "";
	iFrame.style.position = "absolute";
	iFrame.style.border = "0";
	iFrame.style.marginLeft = $("#" + obj_id)[0].style.marginLeft;
	iFrame.style.left = $("#" + obj_id)[0].style.left;
	iFrame.style.top = $("#" + obj_id)[0].style.top;
	iFrame.style.width = $("#" + obj_id)[0].style.width;
	iFrame.style.height = $("#" + obj_id)[0].offsetHeight;
	document.body.appendChild(iFrame);
	cat_PopupIFrame = iFrame;
}

function catDeleteIframe(id)
{
	if (cat_PopupIFrame) {
		document.body.removeChild(cat_PopupIFrame);
		cat_PopupIFrame = null;
	}
}

function catDisableElements(id)
{
	var obj_id = id;
	$("#" + obj_id).css("display", "");
	var h = !window.opera ? document.documentElement.clientHeight:document.body.clientHeight;
	if (window.opera) {
		h = document.documentElement.clientHeight;
	}
	if (document.body.offsetHeight > h) {
		h = document.body.offsetHeight + 30;
	} else if (window.opera) {
		
	}

	$("#" + obj_id)[0].style.height = getDocumentHeight() + 'px';
	$("#" + obj_id)[0].style.width  = getDocumentWidth() + "px";
	if (document.all) {
		$("#" + obj_id)[0].style.width = "100%";
	}

	var selects = document.getElementsByTagName("select");
	for (var i = 0; i < selects.length; i++) {
		selects[i].disabled = true;
	}
}

function catEnableElements(id)
{
	var obj_id = id;
	$("#" + obj_id).css("display", "none");
	var selects = document.getElementsByTagName("select");
	for (var i = 0; i < selects.length; i++) {
		selects[i].disabled = false;
	}
}

function catOpenWaiting()
{
	id = "waiting";
	catOpenModal(id);
}

function catCloseWaiting()
{
	id = "waiting";
	catCloseModal(id);
}

//Размер документа по вертикали  
function getDocumentHeight()  
{  
    return (document.body.scrollHeight > document.body.offsetHeight)?document.body.scrollHeight:document.body.offsetHeight;  
}  
  
//Размер документа по горизонтали  
function getDocumentWidth()  
{  
    return (document.body.scrollWidth > document.body.offsetWidth)?document.body.scrollWidth:document.body.offsetWidth;  
}

function showProcessBar()
{
	catDisableElements("waiting_opat");
	catOpenWaiting();
}

function hideProcessBar()
{
	catCloseWaiting();
	catEnableElements("waiting_opat");
}
