function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	return yScroll;
}

function maskType() {
	return (document.all) ? "Img" : "Div";
}
  
  
function theSubmit(theForm) {
	theForm.submit();
	return true;
}
function checkChrs(str) {
	for(i=0;i<str.length;i++) {
		var ch = str.charAt(i);
		if(ch != '0' && ch != '1' && ch != '2' && ch != '3' && ch != '4' && ch != '5' && ch != '6' && ch != '7' && ch != '8' && ch != '9') {
			return false;
		}
	}
	return true;
}
function checkEmailOLD(str) {
	x = new RegExp("\\w+@\\w+\\.\\w");
	//alert(x.test(str));
	if (x.test(str)) {
		return true;
	} else {
		return false;
	}
}
function s_sel(w) {
		var div = document.getElementById('sadv');
	    var inp = div.getElementsByTagName('input');
	    for (var i = 0; i < inp.length; i=i+1) {
	    	var obj = inp[i];
			obj.name==w ? obj.value='1' : obj.value='0';
        }
        document.snavform.submit();
}
function checkEmail(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)

	if (str.indexOf(at)==-1){
		return false;
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		return false;
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false;
	}
	if (str.indexOf(at,(lat+1))!=-1){
		return false;
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false;
	}
	if (str.indexOf(dot,(lat+2))==-1){
		return false;
	}	
	if (str.indexOf(" ")!=-1){
		return false;
	}
	return true;
}
function setPos(obj,s) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	s.style.top = curtop - 203 + 'px';
	s.style.left = curleft + 'px';
}
function check_tipform(frm) {
	if(frm.to_email.value == "" || frm.to_email.value.indexOf("@") == -1) {
		alert("Du m&aring;ste fylla i din kompis e-postadress!");
		frm.to_email.focus();
		return false;
	}
	if(frm.from_name.value == "") {
		alert("Du m&aring;ste fylla i ditt namn!");
		frm.from_name.focus();
		return false;
	}
	if(frm.from_email.value == "" || frm.from_email.value.indexOf("@") == -1) {
		alert("Du m&aring;ste fylla i din e-postadress!");
		frm.from_email.focus();
		return false;
	}
	return true;
}
function addEvent( obj, type, fn ){  // the add event function
    if (obj.addEventListener) obj.addEventListener( type, fn, false );
    else if (obj.attachEvent) {
      obj["e"+type+fn] = fn;
      obj[type+fn] = function() {
        obj["e"+type+fn]( window.event );
      };
      obj.attachEvent( "on"+type, obj[type+fn] );
    }
  }
 
function showPopMenu(sid, elPlacement, xOffset, yOffset) {
	popEl = document.getElementById(sid);
	
	if(popEl.style.display=="") {
		popEl.style.display="none";
		return false;
	}

	if ( elPlacement != null ) {
		var pt = getAbsolutePosition(elPlacement);
		popEl.style.top = (pt.y + yOffset) + 'px';
		popEl.style.left = (pt.x + xOffset) + 'px';
	}
	
	popEl.style.display="";

	o = document.getElementById('mask' + maskType());
	o.style.display = '';
	o.style.height = documentHeight() + 'px';
	o.style.overflow = 'hidden';
	o.style.width = documentWidth() + 'px';
}

function getAbsolutePosition(elem) {
  	var r = { x: elem.offsetLeft, y: elem.offsetTop };
  	if (elem.offsetParent) {
		while (elem = elem.offsetParent) {
			r.x += elem.offsetLeft;
			r.y += elem.offsetTop;
		}
  	}
  	return r;
}
function documentWidth() {
	return (window.opera ? document.documentElement.clientWidth : document.body.offsetWidth)
}
function documentHeight() {
	return (window.opera ? document.documentElement.clientHeight : document.body.offsetHeight)
}


var popMgr = {
  pels:      new Array(),
  add:        function(i){
	popMgr.pels.push(document.getElementById(i));

  }
};

function hidePopups() {
	for(var i=0;i<popMgr.pels.length;i++) {
	if (window.report && popMgr.pels[i].id==report.holder.id)
		report.holder.innerHTML=report.htmlsave;
	popMgr.pels[i].style.display='none';
		
	}
	document.getElementById('mask' + maskType()).style.display='none';
}

var loader = {
  body:        false,
  loader:      false,
  init:        function(){
    if( !document.getElementById ||
        !document.getElementsByTagName ) return;
        
	this.body = document.getElementsByTagName('body')[0];
    this.loader = document.createElement( 'div' );
    this.loader.setAttribute( 'id', 'loading' );
	this.loader.className='loader';
    this.loader.appendChild( document.createTextNode('Laddar...\u2026'));
  },
  buildLoader: function() {
  	this.loader.style.marginTop=getPageScroll()+"px";
    this.body.appendChild(this.loader);
  },
  killLoader:  function() {
    this.body.removeChild(this.loader);
  }

};

// addEvent( window, 'load', function(){ loader.init(); } );

