function $(i){return document.getElementById(i);}
function initiate() {
	//$('search-entry').onfocus = function() { $('search-entry').style.backgroundImage = 'url(/images/nav-bg-inv.png)'; }
	//$('search-entry').onblur = function() { $('search-entry').style.backgroundImage = 'url(/images/nav-bg.png)'; }
    iconTitles();
    if ((document.body.filters)) {
        iePng();
        var isIe = true;
    }
    else {
        var isIe = false;
    }
}

function selectDropdown(value, dropdownId) {

    dropdown = document.getElementById(dropdownId);
    for (var i = 0; i < dropdown.options.length; i++) {
        if (dropdown.options[i].value == value) {
       
            dropdown.options[i].selected = true;
        }
    }
}

// Gets the style on an object including those set
// from CSS style sheets.
function getStyle(element) {
    var computedStyle;
    if (typeof document.defaultView != 'undefined' && typeof document.defaultView.getComputedStyle != 'undefined') {
        computedStyle = document.defaultView.getComputedStyle($(element), '');
    }
    else if (typeof $(element).currentStyle != 'undefined') {
        computedStyle = $(element).currentStyle;
    }
    else {
        computedStyle = $(element).style;
    }
    return computedStyle;
}

function ajaxError(t) {
    alert('An error occured: ' + t.status + ' ' + t.statusText);
}

// This function fixes PNGs for IE.
function iePng() {
    // Fix HX's with background images.
    var allElements = document.all;
    for( var i=0; i < allElements.length; i++ ){
        var element = allElements[i];
        var bg    = element.currentStyle.backgroundImage;
        if (bg && bg.substring(bg.length-5, bg.length-2).toUpperCase() == "PNG") {
            if (bg.indexOf('/icons/') == 1) {
                //alert(element.className);
                var src = bg.substring(5,bg.length-2);
                element.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='crop')";
                element.style.backgroundImage = "url(/images/blank.gif)";
            }
        }
    }
    for(var i=0; i<document.images.length; i++) {
        var img = document.images[i]
        var imgName = img.src.toUpperCase()
        if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
            img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + img.src + "', sizingMethod='stretch');" ;
            width = img.width;
            height = img.height;
            img.src = '/images/blank.gif';
            img.height = height;
            img.width = width;
        }
    }
}

function iconTitles() {
    for( var i=0; i < document.images.length; i++ ){
        var img = document.images[i];
        var imgName = img.src.toUpperCase() 
        if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
            if (img.src.indexOf('/icons/') != -1 && img.title == '') {
            //alert(img.title);
                if (img.src.indexOf('delete') != -1) {
                    img.title = 'Delete';
                }
                else if (img.src.indexOf('add') != -1) {
                    img.title = 'New';
                }
                else if (img.src.indexOf('edit') != -1 || img.src.indexOf('pencil') != -1) {
                    img.title = 'Edit';
                }
            }
        }
    }
}

// Vote on poll
function voteOnPoll(pollId, optionId) {
    var voteUrl = "/poll?ajax&pid=" + pollId + "&aid=" + optionId;
    new Ajax.Request(voteUrl, {onSuccess:function(t) {
        new Ajax.Updater('poll', '/poll?ajax');
    }, onFailure:ajaxError});
    return;
}