/* visfreaks.nl runtime javascript functions */

function getNewImages()
{
    ret = "";

    cat = document.getElementById('category');
    if (cat.selectedIndex > 0)
    {
        ret += "/category/" + cat.options[cat.selectedIndex].value;
    }
   
    loc = document.getElementById('location');
    if (loc.selectedIndex > 0)
    {
        ret += "/location/" + loc.options[loc.selectedIndex].value;
    }
    
    bai = document.getElementById('bait');
    if (bai.selectedIndex > 0)
    {
        ret += "/bait/" + bai.options[bai.selectedIndex].value;
    }

    yea = document.getElementById('date-year');
    if (yea.selectedIndex > 0)
    {
        ret += "/year/" + yea.options[yea.selectedIndex].value;
    }

    mnd = document.getElementById('date-month');
    if (mnd.selectedIndex > 0)
    {
        ret += "/month/" + mnd.options[mnd.selectedIndex].value;
    }

    dy = document.getElementById('date-day');
    if (dy.selectedIndex > 0)
    {
        ret += "/day/" + dy.options[dy.selectedIndex].value;
    }

    if (ret == "")
    {
        location.href= "/catch/images.html";
    }
    else
    {
        location.href= "/catch/images" + ret;
    }
}

function getNewVideos()
{
    ret = "";

    cat = document.getElementById('category');
    if (cat.selectedIndex > 0)
    {
        ret += "/category/" + cat.options[cat.selectedIndex].value;
    }
   
    if (ret == "")
    {
        location.href= "/catch/videos.html";
    }
    else
    {
        location.href= "/catch/videos" + ret;
    }
}

function doMediaType(inStr)
{
    vidSrc = document.getElementById('vid');
    imgSrc = document.getElementById('img');

    if (inStr == "vid")
    {
        vidSrc.style.display = 'block';
        imgSrc.style.display = 'none';
    }
    else
    {
        vidSrc.style.display = 'none';
        imgSrc.style.display = 'block';
    }

    document.getElementById('action_upload').disabled = false;
}

function imageDelete(id)
{
    f  = document.getElementById("img" + id);
    f1 = document.getElementById("file" + id);

    if (f1.value == "0")
    {
         // show f1
        f1.value = "1";
        f.src = '/mediaimage/' + id + '/121';
    }
    else
    {
        // hide f1
        f1.value = "0";
        f.src = '/cache/nosavepicture.png';
    }
}

function goToSelect(url, id)
{ 
     location.href=url + document.getElementById(id).options[document.getElementById(id).selectedIndex].value;
}

var topicOption = 0;
function topicOptions() 
{
    topicOption = 1 - topicOption;
    if (topicOption == 1) 
    {
        document.getElementById('topicOptionDiv').style.display='block';
    } 
    else 
    {
        document.getElementById('topicOptionDiv').style.display='none';
    }
}
                    
function insertPicture(newText) 
{
    document.getElementById('message').innerText += newText + " ";
}



var resized_images = new Array();

if (document.all)
    var maxImageWidth = 600;
else if (document.layers)
    var maxImageWidth = 600;

    function fullsize() {
        var oSource = window.event.srcElement.src;
        tempvar = resized_images[oSource];
        showpopupwindow = window.open('', "_blank","toolbar=no,location=no,menubar=no,status=no,left=0,top=0"+tempvar);
        showpopupwindow.document.writeln("<html><head><title>*kuch*: " + unescape(oSource) +  "</title>");
        showpopupwindow.document.writeln("</head><body topmargin=\"0\" leftmargin=\"0\" marginheight=\"0\" marginwidth=\"0\">");
        showpopupwindow.document.writeln("<img src=\"" + oSource + "\" onclick=\"window.close()\" title=\"Klik om dit venster te sluiten\">");
        showpopupwindow.document.writeln("</body></html>");
        showpopupwindow.document.close();
    }

    function resize(image){
        if(!image){
            var image = window.event.srcElement;
        }

        width = image.width;
        height = image.height;
        var url = image.src;

        if(width>maxImageWidth){
            resized_images[url] = ",width="+width+",height="+height;
            image.width = maxImageWidth;
            image.title = 'Originele grootte: '+width+'x'+height;
            image.style.border = "dashed 1px red";
            image.style.cursor = "hand";
            image.onclick = fullsize;
            image.height = Math.floor(height/(width/maxImageWidth));
        }
    }

    function check_images(){
        count = document.images.length;
        i = 0;

        while(count>i){
            imgurl = document.images[i].src;

            if(document.images[i].complete){
                    resize(document.images[i]);
            }else{
                document.images[i].onload = resize;
            }
        i++;
    }
}





function show(id)
{
    if (oldId != 0)
    {
        document.getElementById(oldId).style.display = 'none';
    }

    oldId = id
    document.getElementById(id).style.display = 'block';
}

function openclose(id)
{
    d = document.getElementById(id);

    if (d.style.display == 'block')
    {
        d.style.display = 'none';
    }
    else
    {
        d.style.display = 'block';
    }
}

var oldId = 0;

/* comments */
function showReact()
{
    x = document.getElementById('react');
    (x.style.display == 'block') ? x.style.display = 'none' : x.style.display = 'block';
}

