﻿function searchFieldFocus(element) {
    if (element != null) 
    {
        element.style.color = '#000000';
        if (element.value.substr(0, 1) == '-' || element.value.substr(0, 1) == '€') 
        {
            element.value = '';
        }
    }
}

function searchFieldBlur(element, hint)
{
    var input = document.forms['aspnetForm'].elements[element.id];
    if (input != null)
    {
        if (input.value == '')
        {
            input.style.color = '#808080';
            input.value = hint;
        }
    }
}

function thumbNav(url)
{
  window.location.href=url;
  return false;
}

function quickSearch()
{
    var query = '';
    var sep = '?';
    
    var keywords = document.forms['aspnetForm'].searchKeywords.value;
    if (keywords.length > 0 && keywords.substr(0,1) != '-')
    {
        query += (sep + 'q=' + keywords);
        sep = '&';
    }
    
    var minPrice = document.forms['aspnetForm'].minPrice.value;
    if (minPrice.length > 0 && minPrice.substr(0,1) != '€')
    {
        query += (sep + 'minPrice=' + minPrice);
        sep = '&';
    }    
    
    var maxPrice = document.forms['aspnetForm'].maxPrice.value;
    if (maxPrice.length > 0 && maxPrice.substr(0,1) != '€')
    {
        query += (sep + 'maxPrice=' + maxPrice);
    }    
    
    if (query != '')
    {
        window.location.href= '/vind-kunst' + query;
        return true;
    }
    return false;
}

var popUpTimeout;

function showPopUp()
{
    var popUpDiv = document.getElementById('artworkPopUp');
    if (popUpDiv != null)
    {        
        popUpDiv.style.display = 'block';  
    }
}

function artPopUp(element, imgfile)
{
    hideArtPopUp();
    
    if (element != null && imgfile != null && imgfile != '')
    {
        var popUpDiv = document.getElementById('artworkPopUp');
        var popUpImg = document.getElementById('popUpImage');
        if (popUpDiv != null && popUpImg != null)
        {           
            var curLeft = 0, curTop = 0;
            
            curLeft = window.event.clientX;
            curTop = window.event.clientY;                  
            
            if (curLeft > 0 && curTop > 0) // FF returns 0?
            {
                popUpImg.src = imgfile;            
                popUpDiv.style.left = curLeft + 20;
                popUpDiv.style.top = curTop + 50;            
                popUpTimeout = setTimeout('showPopUp()', 500);
            }
        }
    }
}

function hideArtPopUp()
{
    if (popUpTimeout != null)
    {
        clearTimeout(popUpTimeout);
    }
    var popUpDiv = document.getElementById('artworkPopUp');
    if (popUpDiv != null)
    {
        popUpDiv.style.display = 'none';
    }
}