// SWF fix
var bo_noscript_id = 0;
function isIE() {
  var strBrowser = navigator.userAgent.toLowerCase();
  return ((strBrowser.indexOf("msie") > -1 || strBrowser.indexOf("opera") > -1) && strBrowser.indexOf("mac") < 0);
}

function startFix() {
  if (isIE()) {
   document.write('<div style="display: none;" id="bo_noscript_id_' + bo_noscript_id + '">');
  }
}

function endFix() {
  if (isIE()) {
   document.write('</div>');
   var theObject = document.getElementById("bo_noscript_id_" + bo_noscript_id++);
   theObject.outerHTML = theObject.innerHTML;
  }
}
// SWF fix END

// nonemam sakuma tuksos simbolus
function LTrim( value ) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}
// nonemam beigu tuksos simbolus
function RTrim( value ) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}
// nonemam sakuma un beigu tuksos simbolus
function trim( value ) {
	return LTrim(RTrim(value));
}
// mail too antispams :)
function m2(ne,ht) {
      window.location.href = "mailto:"+ne+"@"+ht;
}

function hidediv(id) {
	// atskirigo parluku drosa funkcija, kas pasleps div slanus
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

function showdiv(id) {
	// atskirigo parluku drosa funkcija, kas paradiis konkreeto div slaani

	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}


/* custom lboxis */
function showLbox(layer,wi,he){
  // for IE6.0
  if ((BrowserDetect.browser == "Explorer") && (BrowserDetect.version<7)) {
    if (document.body.clientHeight > document.documentElement.clientHeight ) {
      document.getElementById('lbox_overlay').style.height = document.body.clientHeight;
    } else {
      document.getElementById('lbox_overlay').style.height = document.documentElement.clientHeight;
    }

    if (document.body.clientWidth > document.documentElement.clientWidth ) {
      document.getElementById('lbox_overlay').style.width = document.body.clientWidth;
    } else {
      document.getElementById('lbox_overlay').style.width = document.documentElement.clientWidth;
    }
  }

  if(wi > 0){document.getElementById('lbox_box_'+layer).style.width = wi+"px";}
  if(he > 0){document.getElementById('lbox_box_'+layer).style.height = he+"px";}

  //Show the background overlay and topbox...
  document.getElementById('lbox_overlay').style.visibility = 'visible';
  document.getElementById('lbox_box_'+layer).style.display = 'block';

  window.onscroll = function() {verticallyCenter('lbox_box_'+layer)};

  verticallyCenter('lbox_box_'+layer);
}

function closeLbox(layer){
  //Hide the overlay and tobox...
  document.getElementById('lbox_overlay').style.visibility = 'hidden';
  document.getElementById('lbox_box_'+layer).style.display = 'none';
}

function viewportSize(side) {
  var viewportWidth;
  var viewportHeight;

  // for standards compliant browsers (mozilla/netscape/opera/IE7)
  if (typeof window.innerWidth != 'undefined') {
    viewportWidth = window.innerWidth,
    viewportHeight = window.innerHeight
  }
  // IE6 in standards compliant mode (i.e. with a valid doctype)
  else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
   viewportWidth = document.documentElement.clientWidth,
   viewportHeight = document.documentElement.clientHeight
  }
  // older versions of IE
  else {
   viewportWidth = document.getElementsByTagName('body')[0].clientWidth,
   viewportHeight = document.getElementsByTagName('body')[0].clientHeight
  }

  return (side == 'width' ? viewportWidth : viewportHeight);
}

function verticallyCenter(id) {
  var elementHeight=document.getElementById(id).offsetHeight;
  var elementWidth=document.getElementById(id).offsetWidth;

  var winScrollPos = document.documentElement.scrollTop;
  if (winScrollPos == 0){
      if (window.pageYOffset)
          winScrollPos = window.pageYOffset;
      else
          winScrollPos = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
  }

  document.getElementById(id).style.top = winScrollPos + (viewportSize('height') - elementHeight)/2+"px";
  document.getElementById(id).style.left = (viewportSize('width') - elementWidth)/2+"px";
}
/* lboxis END */

function ausupBtnOn(){
   o = document.getElementById('augBtnDiv'); if(o){ o.className = 'footer_2_augsup_on'; }
}

function ausupBtnOff(){
   o = document.getElementById('augBtnDiv'); if(o){ o.className = 'footer_2_augsup'; }
}

function skatitKarti(){
   // paradam lielu gmaps karti ieksh lbox
   var d = '<iframe width="520" height="420" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=terbatas+15+riga+latvia&amp;sll=37.0625,-95.677068&amp;sspn=33.352165,73.300781&amp;ie=UTF8&amp;hq=&amp;hnear=15+T%C4%93rbatas+iela,+R%C4%ABga+1011,+Latvia&amp;ll=56.959859,24.12632&amp;spn=0.005605,0.019183&amp;z=14&amp;output=embed"></iframe>';
   o = document.getElementById('gMapsLay');
   if(o){
      o.innerHTML = d;
      showLbox('map');
   }
}

function skatitKartiIMG(){
   // paradam lielu attela veida karti ieksh lbox
   var d = '<img src="/usr/maps/Rigas_40vsk_map.gif" alt="Rīgas 40. vidusskola map">';
   o = document.getElementById('gMapsLay');
   if(o){
      o.innerHTML = d;
      showLbox('map');
   }
}

function mmenuOver(elem){
   //if(elem){ elem.className = 'act'; }
}

function mmenuOut(elem){
   //if(elem){ elem.className = ''; }
}

function showPhotopackImg(imgsrc,w,h,descr){
   var d = '<a href="#" onclick="closeLbox(\'photopack\'); return false;" class="nou"><img src="'+imgsrc+'" width="'+w+'" height="'+h+'" alt=" "></a>';
   if(descr != ''){d = d + '<p style="margin-top:4px; color:#CD6047; font-size:12px;">'+descr+'</p>';}
   o = document.getElementById('photoPackLay');
   if(o){
      o.innerHTML = d;
      showLbox('photopack',(w+20),(h+50));
   }
}