﻿

function doSearch(){
var sq = document.getElementById('query').value;

if (sq.indexOf('..')>-1){sq = sq.replace(/(\.)/g,""); } 

sq = sq.replace("/","");

if (sq.length>1){
location.href='/q/' + encodeURI(sq) + '/'
}

}
function sfoc(){
var si = document.getElementById('query')
if(si.value=='Stad, namn, tjänst, gata...'){si.value='';};
}
function sev(event) {
  if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13))
    {
    doSearch();
    return false;
    } 
    else return true;
}


var lastDiv=null;
var lastSender=null;
function expand(sender,div,target){
    var oDiv = document.getElementById(div)
    
    if (target) {
        sender=document.getElementById(target)
        sender.className='expand';
    }
    
    if (sender.className=='expand'){
        sender.className='minimize'; oDiv.style.display='';
        if (lastSender!=null && lastSender!=sender){lastDiv.style.display='none';lastSender.className='expand';}
        
        lastDiv=oDiv; lastSender=sender;
    }
    else
    {
    sender.className='expand';oDiv.style.display='none';
    }
}

var lastoDiv=null;
var lastoSender=null;
function expandO(sender,div,target){
    var oDiv = document.getElementById(div)
    
    if (target) {
        sender=document.getElementById(target)
        sender.className='expandO';
    }
    
    if (sender.className=='expandO'){
        sender.className='minimizeO'; oDiv.style.display='';
        if (lastoSender!=null && lastoSender!=sender){lastoDiv.style.display='none';lastoSender.className='expandO';}
        
        lastoDiv=oDiv; lastoSender=sender;
    }
    else
    {
    sender.className='expandO';oDiv.style.display='none';
    }
}
function loadscript(url){
        var LoOS
		LoOS = document.createElement('script'); 
        LoOS.type = 'text/javascript'; 
        LoOS.src = url +'&tm=' + new String (Math.random()).substring (2, 11); 
        document.getElementsByTagName('head')[0].appendChild(LoOS);
}
function loadstatic(url){
        var LoOS
		LoOS = document.createElement('script'); 
        LoOS.type = 'text/javascript'; 
        LoOS.src = url;
        document.getElementsByTagName('head')[0].appendChild(LoOS);
}

/*  KOMMUN ORT LOADER */
function load_orter(sender,komtitle, komid, target){
    var otarget = document.getElementById(target)
    if (sender.className=='up'){
        otarget.style.display='none';
        sender.className='drop';
    }else
    {
        sender.className='up';
        otarget.style.display='';
        
        if (otarget.innerHTML==''){
            otarget.innerHTML="Laddar orter..."
            loadstatic('/visa/kommun_loadort.aspx?target=' + target +'&komid='+komid +'&komtitle='+komtitle +'&ver=1')
        }
    }


}

function setup(){
var links=document.getElementsByTagName("a");
for(i=0;i<links.length;i++){
    if ((links[i].className  == "expO")){
    links[i].onclick=exp; // "expandO(this,''," + links[i].getAttribute("rel") + ")";
    }
    }

var divs=document.getElementsByTagName("div");
for(i=0;i<divs.length;i++){
    if (divs[i].className.indexOf("div")>-1){
    divs[i].style.display='none';
    }
    }
}


//window.onload=setup;


function exp(e){
var oDiv = document.getElementById(this.getAttribute("rel"));
if (this.className=='expO'){
        this.className='minO'; oDiv.style.display='';
        if (lastoSender!=null && lastoSender!=this){lastoDiv.style.display='none';lastoSender.className='expO';}
        
        lastoDiv=oDiv; lastoSender=this;
    }
    else
    {
    this.className='expO';oDiv.style.display='none';
   }
}



function unblockpage(){
 
document.body.style.overflow = '';
var bk = document.getElementById("block");
bk.style.display='none';
bk = document.getElementById("blockcontent");
bk.style.display='none';
}

// ///////////////////////////////////////////////////
// BLOCK CONTENT
//
function blockpage(html)
{
 //alert('blocking');
var bk = document.createElement("div");
var ps = getPageSize();
bk.onmousedown = "return false;"
bk.onclick = "return false;"
bk.onmousemove = "return false;"
bk.onmouseup = "return false;"
bk.ondblclick = "return false;"
bk.style.position='absolute';
bk.style.left='0px';
bk.style.top='0px';
bk.style.width=ps[0] + 'px';
bk.style.height=ps[1] + 'px';
document.body.style.overflow = 'hidden';
bk.style.backgroundColor = '#aaa';

bk.id="block";
 

var bc = document.createElement("div");
bc.innerHTML ='<center><table><tr><td><div id="blockinnercontent"><div onclick="unblockpage()" id="blockhead">Stäng annonsen <b>X</b></div>' + html + '</div></td></table></center>';
bc.id="blockcontent";
bc.style.position='absolute';
bc.style.width=ps[0] + 'px';
bc.style.left='0px';
bc.style.top='0px';

var objBody = document.getElementsByTagName("body").item(0);
objBody.insertBefore(bk, objBody.firstChild);
objBody.insertBefore(bc, objBody.firstChild);


    if (document.all){
		document.body.onresize = resizeblock;
	} else {
  		if (window.addEventListener) {
      		window.addEventListener("resize", resizeblock, false);
   		} else {
      		window.attachEvent("resize", resizeblock);
		}
	}
}

function resizeblock(){
document.body.style.overflow = 'hidden';
var bk = document.getElementById("block");
var bc = document.getElementById("blockcontent");
    if (bk){
            var ps = getPageSize()
            bk.style.width=ps[0] + 'px';
            bk.style.height=ps[1] + 'px';
            bc.style.width=ps[0] + 'px';
            }
}


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;
	}

	//pageWidth=xScroll+windowWidth;
	
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

