idCache = {};
function ShowContent (ABlockId, AID, AType) 
{
	var xmlHttp = new JsHttpRequest();
	if ((AID != '') && (AType !=''))
	{
		
		document.getElementById(ABlockId).innerHTML = '<a href="javascript:;"><p id="close" onClick="HideModalForm(\'modal\')"><b>Закрыть</b></p></a><img src="'+'http://' + document.domain + '/templates/img/loading.gif" /><p><b>Идет загрузка...</b></p>';
		xmlHttp.onreadystatechange = function() 
		{
			if (xmlHttp.readyState == 4) 
			{
				document.getElementById(ABlockId).innerHTML = '<a href="javascript:;"><p id="close" onClick="HideModalForm(\'modal\')"><b>Закрыть</b></p></a>'+xmlHttp.responseText;
			}
		}
		// Prepare request object (automatically choose GET or POST).
		//document.write(ADest);
		xmlHttp.open(null, 'http://' + document.domain + '/showmedia.php', true);
    	// Send data to backend.
    	xmlHttp.send( { q: AType, id: AID } );
    }
	else
	{
		document.getElementById(ABlockId).innerHTML = "<b>Ошибка в запросе!</b>"
	}
    
}

function ShowModalForm (formId, AId, AType)
{
	Show (formId);
	var shadow = GetById ('shadow');
	var login_form = GetById ('login');
	var window_height = document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
	var page_height = GetYScroll() + 10;
	var result_height = window_height > page_height ? window_height : page_height; 
	shadow.style.height = result_height + 'px';
	Show (shadow); 
	ShowContent ( formId, AId, AType); 
}

function ShowImage (formId, AId)
{
	Show (formId);
	var shadow = GetById ('shadow');
	var login_form = GetById ('login');
	var window_height = document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
	var page_height = GetYScroll() + 10;
	var result_height = window_height > page_height ? window_height : page_height; 
	shadow.style.height = result_height + 'px';
	Show (shadow); 
	//ShowContent ( formId, AId, AType); 
	document.getElementById(formId).innerHTML = '<a href="javascript:;"><p id="close" onClick="HideModalForm(\'modal2\')"><b>Закрыть</b></p></a><img src="'+AId+'" />';

}
 

function Show (element) 
{ 
	if (!element.style) 
	{ 
		element = GetById (element); 
	} 
	if (element) 
	{ 
		element.style.display = 'block'; 
	} 
}

function GetById (itemId) 
{ 
	var cached = idCache[itemId];
	if (!cached) 
	{ 
		cached = document.getElementById (itemId); 
		idCache[itemId] = cached; 
	} 
	return cached; 
}
function GetYScroll() 
{ 
	yScroll = 0; 
	if (window.innerHeight && window.scrollMaxY || window.innerWidth && window.scrollMaxX) 
	{ 
		yScroll = window.innerHeight + window.scrollMaxY; xScroll = window.innerWidth + window.scrollMaxX; 
		var deff = document.documentElement; 
		var wff = (deff&&deff.clientWidth) || document.body.clientWidth || window.innerWidth || self.innerWidth; 
		var hff = (deff&&deff.clientHeight) || document.body.clientHeight || window.innerHeight || self.innerHeight; 
		xScroll -= (window.innerWidth - wff); 
		yScroll -= (window.innerHeight - hff); 
	} 
	else if (document.body.scrollHeight > document.body.offsetHeight || document.body.scrollWidth > document.body.offsetWidth) 
	{ // all but Explorer Mac 
		yScroll = document.body.scrollHeight; xScroll = document.body.scrollWidth; 
	} 
	else 
	{ // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari 
		yScroll = document.body.offsetHeight; xScroll = document.body.offsetWidth; 
	} 
	return yScroll; 
}
function Hide (element) { if (!element.style) { element = GetById (element); } if (element) { element.style.display = 'none'; } }
function ShowHide (element) { if (!element.style) { element = GetById (element); } if (element.style.display == 'block') { element.style.display = 'none' } else { element.style.display = 'block' } }
function HideModalForm (formId) { Hide (formId); Hide ('shadow'); Hide ('modal');}
