﻿function Blind(expandElementId, minValue, maxValue, flowVertical, shrinkElementId) {
    var targetValue;
    
    if (typeof(flowVertical) == 'undefined')
        flowVertical = true;
    
    var expandElement = document.getElementById(expandElementId);
    
    if (flowVertical) {
        if (expandElement.offsetHeight < maxValue)
            targetValue = maxValue;
        else
            targetValue = minValue;
    }
    else {
        if (expandElement.offsetWidth < maxValue)
            targetValue = maxValue;
        else
            targetValue = minValue;
    }
    
    AdjustSize(expandElementId, targetValue, flowVertical, shrinkElementId)
}

function AdjustSize(expandElementId, targetValue, flowVertical, shrinkElementId) {
    if (typeof(flowVertical) == undefined)
        flowVertical = true;
        
    var expandElement = document.getElementById(expandElementId);
    var shrinkElement;
    if (typeof(shrinkElementId) != undefined)
        shrinkElement = document.getElementById(shrinkElementId);
    
    var doExpand = false;
    if (flowVertical)
        doExpand = expandElement.offsetHeight < targetValue;
    else
        doExpand = expandElement.offsetWidth < targetValue;
    
    var step = -2;
    if (doExpand)
        step = 2;
        
    if (flowVertical) {
        expandElement.style.height = (expandElement.offsetHeight + step) + 'px';
        expandElement.style.display = '';
        
        if (shrinkElement) {
            shrinkElement.style.height = (shrinkElement.offsetHeight + (step * -1)) + 'px';
            if (shrinkElement.style.height == '0px')
                shrinkElement.style.display = 'none';
        }
        
        if ((doExpand && expandElement.offsetHeight < targetValue) || (!doExpand && expandElement.offsetHeight > targetValue))
            window.setTimeout("AdjustSize('" + expandElementId + "', " + targetValue + ", " + flowVertical + ", '" + shrinkElementId + "')", 1);
    }
    else {
        expandElement.style.width = (expandElement.offsetWidth + step) + 'px';
        expandElement.style.display = '';
        
        if (shrinkElement) {
            shrinkElement.style.width = (shrinkElement.offsetWidth + (step * -1)) + 'px';
            if (shrinkElement.style.width == '0px')
                shrinkElement.style.display = 'none';
        }
        
        if ((doExpand && expandElement.offsetHeight < targetValue) || (!doExpand && expandElement.offsetHeight > targetValue))
            window.setTimeout("AdjustSize('" + expandElementId + "', " + targetValue + ", " + flowVertical + ", '" + shrinkElementId + "')", 1);
    }
}
function Visible(ElementId,bVisible) {
    var Object = document.getElementById(ElementId);

    if(bVisible) {
        Object.style.display = 'block';
    } else {
        Object.style.display = 'none';
    }
}
//Search Field
var searchDefaultValue = '';
function initiateSearch(id) {
    searchDefaultValue = document.getElementById(id).value;
    document.getElementById(id).className = 'input inactiv';
    document.getElementById(id).onfocus = function() { handleSearch(id, true); };
    document.getElementById(id).onblur = function() { handleSearch(id, false); };
}
function handleSearch(id, b) {
    if (id != null && document.getElementById(id) != null) {
        if (b) {
            if (document.getElementById(id).value == searchDefaultValue) {
                document.getElementById(id).value = '';
                document.getElementById(id).className = 'input';
                
            }
        } else {
            if (document.getElementById(id).value == '') {
                document.getElementById(id).value = searchDefaultValue;
                document.getElementById(id).className = 'input inactiv';
                
            }
        }
    }
}
//round Border
function initiateRoundBorder(id) {
    var parent = document.getElementById(id);
    if (parent) {
        var img = parent.getElementsByTagName('img');
        for (var i = 0; i < img.length; i++) {
            if (img[i].getAttribute('rel') != 'noBorder' &&
            img[i].parentNode.getAttribute('rel') != 'noBorder' &&
            img[i].parentNode.parentNode.getAttribute('rel') != 'noBorder' &&
            img[i].parentNode.parentNode.parentNode.getAttribute('rel') != 'noBorder' &&
            img[i].parentNode.parentNode.parentNode.parentNode.getAttribute('rel') != 'noBorder' && 
            img[i].parentNode.parentNode.parentNode.parentNode.parentNode.getAttribute('rel') != 'noBorder' && 
            img[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.getAttribute('rel') != 'noBorder' && 
            img[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.getAttribute('rel') != 'noBorder') {
                var div0, div1, div2, div3;
                div0 = document.createElement('div');
                div1 = document.createElement('div');
                div2 = document.createElement('div');
                div3 = document.createElement('div');

                
                
                var newData = img[i];
                
                if (newData.getAttribute('align') == 'right') {
                    div0.className = 'roundBorderRight';
                } else {
                    div0.className = 'roundBorderLeft';
                }
                newData.removeAttribute('align');

                img[i].parentNode.replaceChild(div0, img[i]);
                
                div3.appendChild(newData);
                div2.appendChild(div3);
                div1.appendChild(div2);
                div0.appendChild(div1);
            }
        }
    }
}
