//-----------------------------------------------------------------------------
// 1k DHTML API
// specs: http://dithered.com/experiments/1kdhtml/5kentry.html
d=document;l=(d.layers)?1:0;op=navigator.userAgent.toLowerCase().indexOf('opera')!=-1;ie=navigator.userAgent.toLowerCase().indexOf('msie')!=-1;
function gE(e,f){if(l){f=(f)?f:self;V=f.document.layers;if(V[e])return V[e];for(W=0;W<V.length;)return(gE(e,V[W++]));}if(d.all)return d.all[e];return d.getElementById(e);}
function sE(e){if(l)e.visibility='show';else e.style.visibility='visible';}
function hE(e){if(l)e.visibility='hide';else e.style.visibility='hidden';}
function sZ(e,z){if(l)e.zIndex=z;else e.style.zIndex=z;}
function sX(e,x){if(l)e.left=x;else if(op)e.style.pixelLeft=x;else e.style.left=x;}
function sY(e,y){if(l)e.top=y;else if(op)e.style.pixelTop=y;else e.style.top=y;}
function sW(e,w){if(l)e.clip.width=w;else if(op)e.style.pixelWidth=w;else e.style.width=w;}
function sH(e,h){if(l)e.clip.height=h;else if(op)e.style.pixelHeight=h;else e.style.height=h.toString()+'px';}
function sC(e,t,r,b,x){if(l){X=e.clip;X.top=t;X.right=r;X.bottom=b;X.left=x;}else e.style.clip='rect('+t+' '+r+' '+b+' '+x+')';}
function wH(e,h){if(l){Y=e.document;Y.write(h);Y.close();}if(e.innerHTML)e.innerHTML=h;}
// END 1k DHMTL API
//-----------------------------------------------------------------------------
function popWinXL(popurl, winwidth, winheight, xpos, ypos, bMenubar, bToolbar, bLocation)
{
    var poppedWinXL = window.open(popurl,'PopWinXL','toolbar=' + bToolbar + ',personalbar=0,directories=0,location=' + bLocation + ',status=0,menubar=' + bMenubar + ',scrollbars=1,resizable=1,width=' + winwidth + ',height=' + winheight + ',left=' + xpos + ',screenX=' + xpos + ',top=' + ypos + ',screenY=' + ypos + '');
    return poppedWinXL;
}

//-----------------------------------------------------------------------------
function manual(manual_url)
{
//    alert(manual_url);
//    if (manual_url.toString.length == 0)
//        manual_url = 'manual.asp';

    //return window.open(manual_url,'manual_win','toolbar=0,personalbar=0,directories=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,width=300,height=400,left=100,screenX=100,top=50,screenY=50');
    var manualWin = popWinXL(manual_url, 300, 400, 100, 100, 1, 0, 0)
    manualWin.focus();
    return manualWin;
}
//-----------------------------------------------------------------------------
document.getElementsByClass = function(c)
{
    var j = 0;
    var n = '';
    var htmlNode = null;
    var ret = new Array();
    var o = document.all ? document.all : document.getElementsByTagName('*');
    var l = o.length;
    for (i = 0; i < l; i++)
    {
        htmlNode = o[i];
        n = ' ' + htmlNode.className + ' ';
        if (n.indexOf(' ' + c + ' ') != -1)
        {
            ret[j++] = htmlNode;
        }
    }
    return ret;
}
//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
function popWin(theURL,thewidth,theheight)
{
    var poppedWin = window.open(theURL,'PopWin','toolbar=1,personalbar=0,directories=0,location=0,status=0,menubar=1,scrollbars=0,resizable=0,width=' + thewidth + ',height=' + theheight + ',left=100,screenX=100,top=50,screenY=50');
}
//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
function makeHouseboxesClickable()
{
    var htmlHouseboxElement = document.getElementsByClass('housebox');
    var l = htmlHouseboxElement.length;

    for (var i = 0; i < l; i++)
    {
        houseboxElement = htmlHouseboxElement[i];
        houseboxElement.style.cursor = ie ? 'hand' : 'pointer';
        houseboxElement.title = 'Priset gäller grundmålat hus ovan grund, inkl. el, vatten, värme och frakt söder om Dalälven. Tomt och anslutningsavgifter tillkommer, liksom ytskikt (golv, tapeter, lister, kök, skåp och vitvaror).';
        houseboxElement.onclick = function()
        {
            window.location.href = '/hus/?' + this.id.substring(8);
        }
        houseboxElement.onmouseover = function()
        {
            window.status = 'http://' + window.location.hostname + '/hus/?' + this.id.substring(8);
        }
        houseboxElement.onmouseout = function()
        {
            window.status = '';
        }
    }

    return true;
}
//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
// initExternalLinks kontrollerar alla element av typen "a" i dokumentet
// och ger attributet "onclick" värdet "targetBlank" för de element som har
// attributet "rel" med värdet "external", t.ex:
// <a href="foo" rel="external">bar</a>
    function initExternalLinks()
    {
        var htmlLinkElement = null;
        var relSplit = null;
        var htmlLinkElements = document.getElementsByTagName('a');
        var j = htmlLinkElements.length;

        if (document.getElementsByTagName)
        {
            for (var i = 0; i < j; i++)
            {
                htmlLinkElement = htmlLinkElements[i];
                if (!htmlLinkElement.onclick && htmlLinkElement.rel.length > 0)
                {
                    relSplit = htmlLinkElement.rel.split(' ');
                    for (var k = 0; k < relSplit.length; k++)
                    {
                        if (relSplit[k] == 'external')
                        {
                            htmlLinkElement.onclick = function()
                            {
                                window.open(this.href, null, 'directories=0,location=1,menubar=1,personalbar=0,resizable=1,scrollbars=1,status=1,toolbar=1');
                                return false;
                            };
                            break;
                        }
                    }
                }
            }
        }

        return true;
    }
//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
function displayOfficeList(regionId)
{
    var htmlUlistElement = gE('region' + regionId);
    var htmlUlistElements = document.getElementsByTagName('ul');
    var l = htmlUlistElements.length;

    for (var i = 0; i < l; i++)
    {
        element = htmlUlistElements[i];

        if (element.className == 'invisible')
        {
            element.style.display = 'none';
        }
    }

    if (htmlUlistElement)
    {
        htmlUlistElement.style.display = 'block';
        return false;
    }
    else
    {
       return true;
    }
}
//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
function jfrbegagnat_validateForm(htmlFormElement, minPrice)
{
    var htmlInputElement = htmlFormElement.elements['p'];
    var p = htmlInputElement.value.toString();
    p = parseInt(p.replace(/[^\d]/g, ''), 10);
    minPrice = parseInt(minPrice.replace(/[^\d]/g, ''), 10);

    if (/[\d]+/g.test(p))
    {
        htmlInputElement.value = p;

        if (p < minPrice)
        {
            alert('Beloppet på ett begagnat hus måste vara minst ' + minPrice + ' kr.');
            htmlInputElement.focus();
            return false;
        }
        else
        {
            return true;
        }
    }
    else
    {
        alert('Ett belopp på ett begagnat hus måste anges.');
        htmlInputElement.focus();
        return false;
    }
}
//-----------------------------------------------------------------------------

function jfrbegagnatSubmitdisplay_onclick(htmlInputElement)
{
    if (!document.getElementById('displaycalculation'))
    {
        var htmlFormElement = htmlInputElement.form;
        var htmlHiddenInputElement = document.createElement('input');

        htmlHiddenInputElement.setAttribute('type', 'hidden');
        htmlHiddenInputElement.setAttribute('id', 'displaycalculation');
        htmlHiddenInputElement.setAttribute('name', 'displaycalculation');
        htmlHiddenInputElement.setAttribute('value', '1');
        htmlFormElement.appendChild(htmlHiddenInputElement);
    }

    if (document.getElementById('litCalculation'))
    {
        document.getElementById('litCalculation').style.display = 'block';
        htmlInputElement.disabled = true;
        return false;
    }

    return true;

}
//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
function printsubmit_onclick(targetUri, htmlForm)
{
    var query;
    var queryString;
    var i = 0;
    var htmlFormElements = htmlForm.elements;
    var l = htmlFormElements.length

    query = new Array();
    if (htmlForm.elements['ctlTillval'].checked)
        query[i++] = 't=1';
    if (htmlForm.elements['ctlInkop'].checked)
        query[i++] = 'i=1';
    if (htmlForm.elements['ctlStandard'].checked)
        query[i++] = 's=1';
    if (htmlForm.elements['ctlKalkyl'])
        if (htmlForm.elements['ctlKalkyl'].checked)
            query[i++] = 'k=1';

    for (var j = 0; j < l; j++)
    {
        htmlFormElement = htmlFormElements[j]
        if (htmlFormElement.name.substring(0,1) == 'h')
        {
            if (htmlFormElement.checked)
                query[i++] = 'h=' + htmlFormElement.value;
        }
    }

    if (query.length > 0)
    {
        queryString = query.join('&');
        popWin(targetUri + '&' + queryString, 600, 500);
    }
    else
    {
        alert('Välj ett eller flera objekt att skriva ut.');
    }
}
//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
function sverigekarta_onmouseover(regionId)
{
    document.getElementById('sverigekartaimg').src = '/resources/img/kontakt/sverigekarta' + regionId +'.png';
    return true;
}
//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
function sverigekarta_onmouseout()
{
    document.getElementById('sverigekartaimg').src = '/resources/img/kontakt/sverigekarta.png';
    return true;
}
//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
function init()
{
    //ladda extra funktion definierad i sidan
    if (window.page_load)
    {
        window.page_load();
    }

    initExternalLinks();
}
//-----------------------------------------------------------------------------
function disp_confirm(sText)
  {
  var r=confirm(sText)
  if (r==true)
    {
    window.location = "/hus/application.asp?op=logout"
    }
 /* else
    {
   	window.location = ""
    }*/
  }
//-----------------------------------------------------------------------------
//Redirectar till rätt hussida när man klickat på tabellen
function gotoTomt(pageName){
	var fullPath = "/tomter/index.asp?object=" + pageName;
	window.location = fullPath;
}
function gotoOffice(pageName){
	var fullPath = "/kontakt/office.asp?office=" + pageName;
	window.location = fullPath;
}
function gotoPerson(pageName){
	var fullPath = "person.asp?person=" + pageName;
	window.location = fullPath;
}
function gotoOmrade(pageName){
	window.location = pageName;
}
function gotoHus(pageName){
	var fullPath = "/husprogram/" + pageName;
	window.location = fullPath;
}

//-----------------------------------------------------------------------------
window.onload = init;
//-----------------------------------------------------------------------------
