function ge(id) { return(document.getElementById ? document.getElementById(id) : document.all ? document.all[id] : null); }
function isIE() { return('\v'=='v'); }
//function isOpera() { return(navigator.userAgent.toLowerCase().indexOf('opera') > -1); }
var ua = navigator.userAgent.toLowerCase();
var isOpera = (ua.indexOf('opera')  > -1);

function mainLnk() {
	var hr = document.location.href;
	if (hr=='http://www.terra.mu/' || hr=='http://www.terra.mu/index.php') {
		ge('mlnk').style.visibility='hidden';
		ge('m2nd').className='first';
	}
}
 
function getDocumentHeight() {
  return Math.max(document.compatMode != 'CSS1Compat' ? document.body.scrollHeight : document.documentElement.scrollHeight, getViewportHeight());
}
 
function getViewportHeight() {
  return ((document.compatMode || isIE()) && !isOpera) ? (document.compatMode == 'CSS1Compat') ? document.documentElement.clientHeight : document.body.clientHeight : (document.parentWindow || document.defaultView).innerHeight;
}

function setElementOpacity(sElemId, nOpacity) {
  var opacityProp = getOpacityProperty();
  var elem = document.getElementById(sElemId);
  if (!elem || !opacityProp) return; // Если не существует элемент с указанным id или браузер не поддерживает ни один из известных функции способов управления прозрачностью
  if (opacityProp=="filter") { // Internet Exploder 5.5+
    nOpacity *= 100;
    // Если уже установлена прозрачность, то меняем её через коллекцию filters, иначе добавляем прозрачность через style.filter
    var oAlpha = elem.filters['DXImageTransform.Microsoft.alpha'] || elem.filters.alpha;
    if (oAlpha) oAlpha.opacity = nOpacity;
    else elem.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity="+nOpacity+")"; // Для того чтобы не затереть другие фильтры используем "+="
  }
  else // Другие браузеры
    elem.style[opacityProp] = nOpacity;
}
function getOpacityProperty() {
  if (typeof document.body.style.opacity == 'string') // CSS3 compliant (Moz 1.7+, Safari 1.2+, Opera 9)
    return 'opacity';
  else if (typeof document.body.style.MozOpacity == 'string') // Mozilla 1.6 и младше, Firefox 0.8 
    return 'MozOpacity';
  else if (typeof document.body.style.KhtmlOpacity == 'string') // Konqueror 3.1, Safari 1.1
    return 'KhtmlOpacity';
  else if (document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1]>=5.5) // Internet Exploder 5.5+
    return 'filter';
  return false; //нет прозрачности
}

function getPageWidth() {
	if (window.innerHeight && window.scrollMaxY) { // Firefox
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		xWithScroll = document.body.offsetWidth;
  }
	return xWithScroll;
}

function fadePageContent() {
	ge('fadepage').style.display='block';
	ge('fadepage').style.height=getDocumentHeight()+'px';
	setElementOpacity('fadepage',0.85);
}

function unfadePageContent() {
	ge('fadepage').style.height=0;
	ge('fadepage').style.display='none';
}

function includeCSS(src) {
	var html_doc = document.getElementsByTagName('head')[0];
	css = document.createElement('link');
	css.setAttribute('rel', 'stylesheet');
	css.setAttribute('type', 'text/css');
	css.setAttribute('href', src);
	html_doc.appendChild(css);
}

