/**
 * loads the controlwindow
 */
function initme() {
    //initImages();
    //top.frames["hidden"].location.href = "/controller.aspx"
        //Filen finns inte och ovanstående rad kan förmodligen tas bort helt.
    callForPrice(getElementsByPrefixedClassName("price"));
    init_Page();
} window.onload = initme;

function init_Page() {
    if( !document.getElementsByTagName) return;
    var a = document.getElementsByTagName('a');
    for (var i=0; i<a.length; i++) {
        if ( a[i].getAttribute('href') && (
                    a[i].getAttribute('rel') == 'nofollow'
                 || a[i].getAttribute('rel') == 'external')) {
            a[i].target = '_blank';
        }
    }
}

/**
 *
 */
function initImages() {
    var objImages = getElementsByClassName("popImage");
        var strOut = "";
    /*for ( var i in new Image() )
        strOut += i + ", ";
    alert(strOut)*/
    for( var i = 0; i < objImages.length; i++ ) {
        if(imageIsEmpty(objImages[i])) {
            objImages[i].style.display="none";
        } else {
            scaleImage(objImages[i], 150);
        }
    }
}
function imageIsEmpty(inobjImage) {
    return inobjImage.fileSize==-1||!inobjImage.width;
}
/**
 *
 */
function callForPrice(inobjItems) {
    var objArray = new Array();
    var strAtr;
    for( var i = 0; i < inobjItems.length; i++ ) {
        strAtr = inobjItems[i].getAttribute("className") || inobjItems[i].getAttribute("class");
        objArray[objArray.length] = strAtr.replace("price", "");
    }
    top.frames["hidden"].location.href = "priceFetch.aspx?ArticleId=" + objArray.toString();
}
/**
 * getInnerHtml() hämtar angiven html-formaterad fil i /inc/ och visar i frontLeft
 * Ex: <a href="#top" onclick="getInnerHtml('operationell_leasing.htm');">Läs mer</a>
 */
function getXMLHTTPRequest() {
    try {
        req = new XMLHttpRequest();
    } catch(err1) {
        try {
            req = new ActiveXObject("Msxml2.XMLHTTP");
        } catch(err2) {
            try {
                req = new ActiveXObject("Microsoft.XMLHTTP");
            } catch(err3) {
                req = false;
            }
        }
    }
    return req;
}

var http = getXMLHTTPRequest();

var punkter='';

function useHttpResponse() {
    if(http.readyState == 4) {
        if(http.status == 200) {
            var newhtml = http.responseText;
            punkter = '';
            document.getElementById('incDocument').innerHTML = newhtml;
        }
    }
    else {
        punkter+='..';
        document.getElementById('incDocument').innerHTML = "Sidan laddas"+punkter+"";
    }
}

function getInnerHtml(url) {
    myRand = parseInt(Math.random()*99999999999999);
    var requrl = "inc/"+url+"?rand="+myRand;
    http.open("GET", requrl, true);
    http.onreadystatechange = useHttpResponse;
    http.send('null');
}
function closeIncDocCont()
{
    document.getElementById('incDocContainer').style.display='none';
}