function keyboard_ToggleContent(d, t) {
    if (d == null || d.length < 1 || t == null || t.length < 1)
        return;
    var txtFld = document.getElementById(t);

    if (document.getElementById(d).style.visibility == "hidden") {
        var pos = $(t).cumulativeOffset();
        $(d).setStyle(
            { 
                visibility: "visible",
                left: "" + (pos.left-100) + "px",
                top: "" + (pos.top + 30) + "px"
            }
        );
        
        if (txtFld.value == 'Search the site') txtFld.value = '';
    }
    else {
        $(d).setStyle({ visibility: "hidden" });
        
        if (txtFld.value == '')
            txtFld.value = 'Search the site';
    }
}

var shift = 0;
var trigger = 0;
var sh = 0;
var cl = 0;
var winFeedback;

function keyboard_Add(reg_up, reg_down, controlId) {
    var ctrl = document.getElementById(controlId);

    if (trigger == 1) {
        x = reg_down;
        reg_down = reg_up;
        reg_up = x;
        trigger = 0;
    }
    if (shift == 0) {
        ctrl.value = ctrl.value + reg_up;
    }
    else {
        ctrl.value = ctrl.value + reg_down;
    }
}

function keyboard_Backspace(controlId) {
    var e = document.getElementById(controlId);
    e.value = e.value.substr(0, e.value.length - 1);
}

function keyboard_Clear(controlId) {
    var e = document.getElementById(controlId);
    e.value = '';
}

function feedback_ShowWindow(parent) {
    var wndFeedback = $("wndFeedback");
    if (wndFeedback != null) 
        return;
    
    var pos = $("imgFeedback").cumulativeOffset();
    winFeedback = new Window("wndFeedback",
        { className: null, top: "" + (pos.top ) + "px", left: "" + pos.left + "px",
            width: 310, height: 330, title: "", showEffect: Effect.BlindDown,
            showEffectOptions: { duration: 0.5 },
            hideEffect: Effect.SlideUp,
            hideEffectOptions : { duration: 0.5 },
            maximizable: false, minimizable: false, draggable : false
        });
    winFeedback.setHTMLContent("<div class=\"FBack\"><div class=\"FBackNote\">" +
        "We value your feedback. Please share your comments and ideas with us:</div>"+
        "<div class=\"FBackForms\"><input name=\"tbEmailFB\" type=\"text\" value=\"Your email\" id=\"tbEmailFB\" " +
        "onfocus=\"if(this.value == 'Your email') this.value = '';\" "+
        "onblur=\"if(this.value == '') this.value= 'Your email';\" /> "+
        "<select name=\"cbSubjectFB\" id=\"cbSubjectFB\"> "+
        "<option value=\"0\">Message subject</option> "+
        "<option value=\"1\">Suggestion</option> "+
        "<option value=\"2\">Comment</option> "+
        "<option value=\"3\">Problem</option> "+
        "<option value=\"4\">Content request</option> "+
        "</select>"+
        "<br /><textarea name=\"tbMessageFB\" id=\"tbMessageFB\"></textarea>"+
        "</div><br />" +
        "<a href=\"javascript://;\">"+
        "<img name=\"btnSendFB\" id=\"btnSendFB\" width=\"38\" height=\"18\" src=\"/img/btns/send.gif\" alt=\"Send\" " +
        " onclick=\"if ($('tbEmailFB').value=='Your email' || $('cbSubjectFB').options.selectedIndex==0 || $('tbMessageFB')=='') return false; else {feedback_SendForm(); return false; };\" " +
        " style=\"border-width:0px;\" /></a>" +
        "<span class=\"FBackClose\" onclick=\"winFeedback.close();\"><a href=\"#\">close this window </a><a href=\"#\"><img src=\"/img/icons/close.gif\"></a>" +
        "</div>");
    winFeedback.setDestroyOnClose();
    winFeedback.show();
}

function feedback_SendForm() {
    var email = $("tbEmailFB").value;
    var subject = $('cbSubjectFB').options.selectedIndex;
    var message = $("tbMessageFB").value;

    InetCraft.DRMSolution.WebManager.Client.SendFeedback(email, subject, message, feedback_OnSucceeded, feedback_OnFailed);
}

function feedback_OnSucceeded() {
    winFeedback.setHTMLContent("<div class=\"FBack\">Thank you for your comments. We will respond within 1 business day.</div>");
    winFeedback.updateHeight();
    setTimeout(feedback_Close, 4000);
}

function feedback_OnFailed(error) {
    var div = document.createElement('div');
    var text = document.createTextNode(error.get_message());
    div.appendChild(text);
    winFeedback.setHTMLContent("<div class=\"FBack\">" + div.innerHTML + "</div>");
    winFeedback.updateHeight();
    setTimeout(feedback_Close, 5000);
}

function feedback_Close() {
    winFeedback.close();
}

function input_DefaultButtonClick(e, buttonid) {
    var evt = e ? e : window.event;
    if (evt.keyCode == 13) {
        var bt = document.getElementById(buttonid);
        if (bt) {
            bt.click();
            return false;
        }
    }
}
/*
function addEvent(elem, eventType, handler) {
    if (!elem.eventHandlers) elem.eventHandlers = [];
    if (!elem.eventHandlers[eventType]) {
        elem.eventHandlers[eventType] = [];
        if (elem['on' + eventType]) elem.eventHandlers[eventType].push(elem['on' + eventType]);
        elem['on' + eventType] = handleEvent;
    }
    elem.eventHandlers[eventType].push(handler);
}

function removeEvent(elem, eventType, handler) {
    var handlers = elem.eventHandlers[eventType];
    for (var i in handlers) if (handlers[i] == handler) delete handlers[i];
}

function handleEvent(e) {
    var returnValue = true;
    if (!e) e = fixEvent(event);
    var handlers = this.eventHandlers[e.type]
    for (var i in handlers) {
        this.$$handleEvent = handlers[i];
        returnValue = !((returnValue && this.$$handleEvent(e)) === false);
    }
    return returnValue;
}

function fixEvent(event) {
    // add W3C standard event methods
    event.preventDefault = fixEvent.preventDefault;
    event.stopPropagation = fixEvent.stopPropagation;
    return event;
};

fixEvent.preventDefault = function() {
    this.returnValue = false;
};

fixEvent.stopPropagation = function() {
    this.cancelBubble = true;
};

function DisableLink(e) {
    addEvent(e, "click", returnFalse);
}

function returnFalse() {
    return false;
}

function DisableEnableLinks(xHow) {
    objLinks = document.links;
    for (i = 0; i < objLinks.length; i++) {
        objLinks[i].disabled = xHow;
        //link with onclick
        if (objLinks[i].onclick && xHow) {
            objLinks[i].onclick = new Function("return false;" + objLinks[i].onclick.toString().getFuncBody());
        }
        //link without onclick
        else if (xHow) {
            objLinks[i].onclick = function() { return false; }
        }
        //remove return false with link without onclick
        else if (!xHow && objLinks[i].onclick.toString().indexOf("function(){return false;}") != -1) {
            objLinks[i].onclick = null;
        }
        //remove return false link with onclick
        else if (!xHow && objLinks[i].onclick.toString().indexOf("return false;") != -1) {
            strClick = objLinks[i].onclick.toString().getFuncBody().replace("return false;", "")
            objLinks[i].onclick = new Function(strClick);
        }
    }
}

String.prototype.getFuncBody = function() {
    var str = this.toString();
    str = str.replace(/[^{]+{/, "");
    str = str.substring(0, str.length - 1);
    str = str.replace(/\n/gi, "");
    //if (!str.match(/\(.*\)/gi)) str += ")";
    return str;
}
*/
/*
// Modal Dialog Box
// copyright 8th July 2006 by Stephen Chapman
// http://javascript.about.com/
// permission to use this Javascript on your web page is granted
// provided that all of the code in this script (including these
// comments) is used without any alteration
function pageWidth() { return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null; }
function pageHeight() { return window.innerHeight != null ? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null ? document.body.clientHeight : null; }
function posLeft() { return typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0; }
function posTop() { return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0; }
function $(x) { return document.getElementById(x); }
function scrollFix() { var obol = $('ol'); obol.style.top = posTop() + 'px'; obol.style.left = posLeft() + 'px' }
function sizeFix() { var obol = $('ol'); obol.style.height = pageHeight() + 'px'; obol.style.width = pageWidth() + 'px'; }
function kp(e) { ky = e ? e.which : event.keyCode; if (ky == 88 || ky == 120) hm(); return false }
function inf(h) { tag = document.getElementsByTagName('select'); for (i = tag.length - 1; i >= 0; i--) tag[i].style.visibility = h; tag = document.getElementsByTagName('iframe'); for (i = tag.length - 1; i >= 0; i--) tag[i].style.visibility = h; tag = document.getElementsByTagName('object'); for (i = tag.length - 1; i >= 0; i--) tag[i].style.visibility = h; }
function sm(obl, wd, ht) { var h = 'hidden'; var b = 'block'; var p = 'px'; var obol = $('ol'); var obbxd = $('mbd'); obbxd.innerHTML = $(obl).innerHTML; obol.style.height = pageHeight() + p; obol.style.width = pageWidth() + p; obol.style.top = posTop() + p; obol.style.left = posLeft() + p; obol.style.display = b; var tp = posTop() + ((pageHeight() - ht) / 2) - 12; var lt = posLeft() + ((pageWidth() - wd) / 2) - 12; var obbx = $('mbox'); obbx.style.top = (tp < 0 ? 0 : tp) + p; obbx.style.left = (lt < 0 ? 0 : lt) + p; obbx.style.width = wd + p; obbx.style.height = ht + p; inf(h); obbx.style.display = b; return false; }
function hm() { var v = 'visible'; var n = 'none'; $('ol').style.display = n; $('mbox').style.display = n; inf(v); document.onkeypress = '' }
function initmb() {
    var ab = 'absolute'; var n = 'none'; var obody = document.getElementsByTagName('body')[0]; var frag = document.createDocumentFragment();
    var obol = document.createElement('div'); obol.setAttribute('id', 'ol'); obol.style.display = n; obol.style.position = ab; obol.style.top = 0;

    obol.style.left = 0; obol.style.zIndex = 998; obol.style.width = '100%'; frag.appendChild(obol); var obbx = document.createElement('div');
    obbx.setAttribute('id', 'mbox'); obbx.style.display = n; obbx.style.position = ab; obbx.style.zIndex = 999; var obl = document.createElement('span');
    obbx.appendChild(obl); var obbxd = document.createElement('div'); obbxd.setAttribute('id', 'mbd'); obl.appendChild(obbxd); frag.insertBefore(obbx, obol.nextSibling); obody.insertBefore(frag, obody.firstChild);
    window.onscroll = scrollFix; window.onresize = sizeFix;
}
window.onload = initmb;

*/
