
window.onresize = doResize;

function doResize(){
    var screenheight;
 
     // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
     if (typeof window.innerHeight != 'undefined')
     {
          screenheight = window.innerHeight
     }
     
    // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
     else if (typeof document.documentElement != 'undefined'
         && typeof document.documentElement.clientHeight !=
         'undefined' && document.documentElement.clientHeight != 0)
     {
           screenheight = document.documentElement.clientHeight
     }
     
     // older versions of IE
     else
     {
           screenheight = document.getElementsByTagName('body')[0].clientHeight
     }                                                                          

     if(screenheight > 400){
     
        var baseheight = screenheight - 100;
        
        var mapfull = getElement("map");
        var mapcontainer = getElement("mapcontainer");
        var container2 = getElement("container2");
        var container3 = getElement("container3");
        var stackcontainer = getElement("stackcontainer");
        var stackbox1 = getElement("stackbox1");
        var stackbox2 = getElement("stackbox2");
        var stackbox3 = getElement("stackbox3");
        var stackbox4 = getElement("stackbox4");
         
        container2.style.height = (baseheight - 0) + "px";
        stackcontainer.style.height = (baseheight - 0) + "px";
        stackbox1.style.height = (baseheight - 55) + "px";
        stackbox2.style.height = (baseheight - 55) + "px";
        stackbox3.style.height = (baseheight - 55) + "px";
        stackbox4.style.height = (baseheight - 55) + "px";
        container3.style.height = baseheight + "px";
        mapcontainer.style.height = baseheight + "px";
        mapfull.style.height = baseheight + "px";
     }
}


function activateStack(nr, printLoading)
{
    if(nr > 2){
        var container2 = getElement("container2");
        var container3 = getElement("container3");
        container2.style.display = "block";
        container3.style.marginRight = "350px";
    }
    
    var stack1 = getElement("stackbox1");
    var stack2 = getElement("stackbox2");
    var stack3 = getElement("stackbox3");
    var stack4 = getElement("stackbox4");
    stack1.style.display = "none";
    stack2.style.display = "none";
    stack3.style.display = "none";
    stack4.style.display = "none";

    var activestack = getElement("stackbox"+nr);
    var activetab = getElement("stacktab"+nr);
    if(printLoading) activestack.innerHTML = "<img src='images/loading.gif' align='absmiddle'> De gegevens worden geladen...";
    activestack.style.display = "block";
    activetab.style.display = "block";
    
    if(nr == 1){
        setContainer2Width(500);
    } else {
        setContainer2Width(350);
    }
}

function toggleContainer2(){
    var container2 = document.getElementById("container2");
    var container3 = document.getElementById("container3");
    var togglebutton = document.getElementById("togglebutton");
    if(container2.style.display == "none"){
        container2.style.display = "block";
        setContainer2Width(350);
        togglebutton.style.backgroundImage = "url('http://test.weetwaar.nl/images/togglebutton1.png')";
    } else {
        container2.style.display = "none";
        container3.style.marginRight = "0px";
        togglebutton.style.backgroundImage = "url('http://test.weetwaar.nl/images/togglebutton2.png')";
    }
}

function setContainer2Width(width){
    var container2 = document.getElementById("container2");
    var container3 = document.getElementById("container3");
    var toptabbox = getElement("toptabbox");
    var stack = getElement("stackcontainer");
    var stack1 = getElement("stackbox1");
    var stack2 = getElement("stackbox2");
    var stack3 = getElement("stackbox3");
    var stack4 = getElement("stackbox4");
    var tab = getElement("stacktab1");

    widthpx = width + "px";
    toppx = (width - 10) + "px";
    stackpx = (width - 9) + "px";
    tabpx = (width - 237) + "px";
    
    container3.style.marginRight = widthpx;
    container2.style.width = widthpx;
    stack.style.width = widthpx;

    toptabbox.style.width = toppx;
    tab.style.width = tabpx;
    stack1.style.width = stackpx;
    stack2.style.width = stackpx;
    stack3.style.width = stackpx;
    stack4.style.width = stackpx;
    
}

function pause(millis) 
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); } 
while(curDate-date < millis);
} 


function setLocation(name, value, field){
    // homemarker.setPoint(point, 13);
    var address = value + ", Amsterdam, The Netherlands";
    var result;
    var teller = 0;
    document.formWW.locatie.value = "Bezig met zoeken...";
    
    result = geocoder.getLatLng(address, function(point){ 
        if (!point) { 
            alert("Het adres of de postcode '" + value + "' kan niet gevonden worden in Amsterdam"); 
            document.formWW.locatie.value = "";
        } else {
            document.formWW.locatie.value = value + ":"+ point;
            createCookie(name, value + ":"+ point,"730"); 
        } 
    });
    
    while(document.formWW.locatie.value == "Bezig met zoeken..." && teller <= 20){
        pause(500);
        if(teller == 2) alert("Uw locatie wordt aangepast naar: "+field.value);
        field.value = document.formWW.locatie.value;
        teller++;
    }
    return result;
}
 
 
function weetwaarScore(name, score){
    for(i=1; i<=5; i++){
        var img = "star" + name + i;
        document.images[img].src = "images/marker"+ i +"off.png";
    }
    var img = "star" + name + score;
    document.images[img].src = "images/marker"+ score +".png";

    document.form1.elements[name].selectedIndex = score - 1;
}   