function findObj(n, d)
{ 
	var p, i, x;

	if(!d) d = document;
	if((p = n.indexOf("?")) > 0 && parent.frames.length)
	{
		d = parent.frames[n.substring(p + 1)].document;
		n = n.substring(0, p);
	}

	for(i = 0; !x && i < d.forms.length; i++)
	{
		x = d.forms[i][n];
	}
	if(!x)
	{

		if(!(x = d[n]) && d.all)
		{
			x = d.all[n];
		}
		for(i = 0; !x && d.layers && i < d.layers.length; i++)
		{
			x = findObj(n, d.layers[i].document);
		}
		if(!x && document.getElementById)
		{
			x = document.getElementById(n);
		}
	}

	return x;
}

function SetCookie(cookieName,cookieValue,nDays) {

 var today = new Date();

 var expire = new Date();

 if (nDays==null || nDays==0) nDays=1;

 expire.setTime(today.getTime() + 3600000*24*nDays);

 document.cookie = cookieName+"="+escape(cookieValue)

                 + ";expires="+expire.toGMTString();

}

function getCookie(name) {

    var dc = document.cookie;

    var prefix = name + "=";

    var begin = dc.indexOf("; " + prefix);

    if (begin == -1) {

        begin = dc.indexOf(prefix);

        if (begin != 0) return null;

    } else {

        begin += 2;

    }

    var end = document.cookie.indexOf(";", begin);

    if (end == -1) {

        end = dc.length;

    }

    return unescape(dc.substring(begin + prefix.length, end));

}

function closeFAQBlock()
{
	document.cookie = 'hide_faq=1; expires=Thu, 1 Aug 2010 00:00:01 UTC; path=/; domain=newzzz.kz';
	$('faq_block').style.display = 'none';
}


function moveToCenter(id)
{
	var el = $(id);
	var _width = parseInt(el.style.width ? el.style.width : el.offsetWidth);
	var _height = parseInt(el.style.height ? el.style.height : el.offsetHeight);

	if (!_height)
	{
		var _top = jQuery(document).scrollTop()+200;
	}
	else
	{
		var _wh = (window.innerHeight ? window.innerHeight : (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight));
		var _top = (((parseInt(_wh)/2)-(_height/2))+jQuery(document).scrollTop());
	}

	var _left = (((parseInt(jQuery(window).width())/2)-(_width/2)));//+jQuery(document).scrollLeft());

	el.style.top = _top+'px';
	el.style.left = _left+'px';
}

function showLoginForm()
{
	moveToCenter('login_layout_form');
	$('login_layout_form').show();
	showOverlay();
}

function showNewsExportPopup(move_center)
{
	moveToCenter('news_export_popup');

	if (!move_center)
	{
		$('news_export_popup').style.left = '30%';
	}

	showOverlay();
	$('news_export_popup').show();

	$("jscode").select();
}


/*------------------------------------------------------------------------------*/
/* Overlay
/*------------------------------------------------------------------------------*/

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 showOverlay()
{
	var arrayPageSize = getPageSize();
	var objOverlay = $('overlay');
	
	objOverlay.style.width = '100%';
	objOverlay.style.height = (arrayPageSize[1] + 'px');
	
	objOverlay.style.display = 'block';
	Element.setOpacity(objOverlay, 0.5);
}

/*------------------------------------------------------------------------------*/
/* Overlay
/*------------------------------------------------------------------------------*/