// javascript
function addEvent(domObj, eventName, func, useCapture) {
    if (domObj.addEventListener) {
        domObj.addEventListener(eventName, func, useCapture);
        return true;
    }
    else if (domObj.attachEvent) {
        var r = domObj.attachEvent('on' + eventName, func);
        return r;
    }
    else { domObj['on' + eventName] = func; }
}

function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') { window.onload = func; }
    else { window.onload = function() { oldonload(); func(); } }
}

function getElementsByClassName(classname) {
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = document.getElementsByTagName("*");
    for (var i = 0, j = els.length; i < j; i++)
    { if (re.test(els[i].className)) a.push(els[i]); }
    return a;
}

addLoadEvent(runBookmark);

function runBookmark() {
    var bookmark = document.getElementById("bookmark");
    if (!bookmark) { return true; }
    var title = bookmark.getAttribute("title");
    bookmark.onclick = function() { return addBookmark(title, bookmark); };
}

addLoadEvent(openPopup);

function openPopup() {
    var popupLinks = getElementsByClassName("openPopup");
    for (var i = 0; i < popupLinks.length; i++) {
        var trigger = popupLinks[i].getAttribute("className") || popupLinks[i].getAttribute("class");
        switch (trigger) {
            case "openPopup prodPopup":
                popupLinks[i].onclick = function() {
                    return popup(this, "Product", "502", "676", "yes");
                }
                break;
            case "openPopup terms":
                popupLinks[i].onclick = function() {
                    return popup(this, "Terms", "600", "744", "yes");
                }
                break;
            case "openPopup emailFriend":
                popupLinks[i].onclick = function() {
                    return popup(this, "EmailFriend", "440", "439", "");
                }
                break;
            case "openPopup forgotten":
                popupLinks[i].onclick = function() {
                    return popup(this, "forgotten", "440", "251", "");
                }
                break;
            case "openPopup security":
                popupLinks[i].onclick = function() {
                    return popup(this, "forgotten", "440", "360", "");
                }
                break;
        }
    }
}

function popup(vURL, vWinName, vWidth, vHeight, vScrollbar) {
    if (!window.focus) return true;
    var vhref;
    var vSWidth = screen.width;
    var vSHeight = screen.height;
    if (vScrollbar == "yes") { vWidth = new Number(vWidth) + 16 }
    var vleftPos = (vSWidth / 2) - (vWidth / 2);
    var vtopPos = (vSHeight / 2) - (vHeight / 2);
    if (typeof (vURL) == 'string') { vhref = vURL; }
    else { vhref = vURL.href; }
    window.open(vhref, vWinName, 'scrollbars=' + vScrollbar + ',statusbar=no,menubar=0,width=' + vWidth + ',height=' + vHeight + ',left=' + vleftPos + ',top=' + vtopPos);
    return false;
}

function addBookmark(title, url) {
    if (window.sidebar) { window.sidebar.addPanel(title, url, ""); }
    else if (document.all) { window.external.AddFavorite(url, title); }
    else if (window.opera && window.print) { return true; }
}

addLoadEvent(faqClick);
function faqClick() {
    if (!document.getElementById("questions")) { return false; }
    var QBox = document.getElementById("questions");
    var questionList = QBox.getElementsByTagName("a");
    if (questionList.length < 1) return false;
    for (var i = 0; i < questionList.length; i++) {
        var thisq = i + 1; questionList[i].onclick = function() {activateTip(this.id); return true;}
    }
}
   
var last = 'q1';
function activateTip(which) {
    toTheTop();
    document.getElementById(which + '_a').className = 'question on';
    last = which;
}

function toTheTop() {
    document.getElementById(last + '_a').className = "question"; 
}

function LimitTextAreaSize(obj, limit) {
    var val = obj.value;
    if (val.length > limit) {
        obj.value = val.substr(0, limit);
        return false;
    }
    return true;
}


function SetErrorClassName(validator, errorCssClassName, isError) {
    var strControlToValidate = validator.controltovalidate;
    var field = document.getElementById(strControlToValidate);
    if (field != null) {
        if (field.parentNode != null) {
            var container = field.parentNode;
            if (isError) {
                if (container.className.indexOf(errorCssClassName) == -1) {
                    container.className = container.className + ' ' + errorCssClassName;
                }
            }
            else {
                if (container.className.indexOf(errorCssClassName) >= 0) {
                    container.className = container.className.substring(0, container.className.indexOf(' ' + errorCssClassName));
                }
            }
        }
    }
}

function SetParentClassName(validator, cssClassName) {
    var strControlToValidate = validator.controltovalidate;
    var field = document.getElementById(strControlToValidate);
    if (field != null) {
        if (field.parentNode != null) {
            var container = field.parentNode;
            if (container.className != null) { container.className = cssClassName; }
        }
    }
}