﻿function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

function editPopLinks() {
    var links = document.getElementsByTagName('a');
    for (var i = links.length; i !== 0; i = i - 1) // Reverse order for speed.
    {
        var a = links[i - 1];
        if (!a.href) {
            continue;
        } else if (a.getAttribute('rel') == 'pop' || a.getAttribute('rel') == 'pop nofollow') {
            a.setAttribute('target', '_blank');
        }
    }
}

function addSelectWrappers() {
    var selects = document.getElementsByTagName('select');
    for (var i = selects.length; i !== 0; i = i - 1) // Reverse order for speed.
    {
        // Put a <span class="select-box"> ... </span> around each <select>...</select> element.
        var node = selects[i - 1];
        var elem = document.createElement('span');
        elem.className = 'select-box';
        node.parentNode.insertBefore(elem, node);
        elem.appendChild(node);
        
        // Put a dynamic JavaScript call to the YAHOO.Hack to expand <select> elements in IE, right after the </span> tag we just added.
//        var nodeID = node.id;
//        var scriptNode = document.createElement('script')
//        scriptNode.setAttribute('type', 'text/javascript');
//        var inlineScript = '/*<![CDATA[*/var ' + nodeID + ' = new YAHOO.Hack.FixIESelectWidth(\'' + nodeID + '\');/*]]>*/';
//        scriptNode.text = inlineScript;
//        elem.parentNode.appendChild(scriptNode);
    }
}

addLoadEvent(editPopLinks);

function textCounter(field, countfield, maxlimit) {
    // Original:  Ronnie T. Moore
    // Web Site:  The JavaScript Source

    // This script and many more are available free online at
    // The JavaScript Source!! http://javascript.internet.com

    // Dynamic 'fix' by: Nannette Thacker
    // Web Site: http://www.shiningstar.net

    // Countfield made optional and scrollTop added by: Charlie Sweet
    // Web site: http://www.ascedia.com
    
    if (field.value.length > maxlimit) {
        // if too long...trim it!
        field.value = field.value.substring(0, maxlimit);
        field.scrollTop = field.scrollHeight;
    } else if (countfield != null) {
        // otherwise, update 'characters left' counter
        countfield.value = maxlimit - field.value.length;
    }
}

