﻿$(function() {

    /*
    The viewport object is mainly for the cross-browser mess
    that is unfortunately necessary to get a DIV to center.

        There is also an officially supported plugin called "Dimensions"
    that can manage some of this on your own projects. Check it out at:

        http://jquery.com/plugins/project/dimensions
    */

        var viewport = {
            o: function() {
                if (self.innerHeight) {
                    this.pageYOffset = self.pageYOffset;
                    this.pageXOffset = self.pageXOffset;
                    this.innerHeight = self.innerHeight;
                    this.innerWidth = self.innerWidth;
                } else if (document.documentElement && document.documentElement.clientHeight) {
                    this.pageYOffset = document.documentElement.scrollTop;
                    this.pageXOffset = document.documentElement.scrollLeft;
                    this.innerHeight = document.documentElement.clientHeight;
                    this.innerWidth = document.documentElement.clientWidth;
                } else if (document.body) {
                    this.pageYOffset = document.body.scrollTop;
                    this.pageXOffset = document.body.scrollLeft;
                    this.innerHeight = document.body.clientHeight;
                    this.innerWidth = document.body.clientWidth;
                }
                return this;
            },
            init: function(el) {
                $(el).css("left", Math.round(viewport.o().innerWidth / 2) + viewport.o().pageXOffset - Math.round($(el).width() / 2));
                $(el).css("top", Math.round(viewport.o().innerHeight / 2) + viewport.o().pageYOffset - Math.round($(el).height() / 2));
            }
        };
//        $(".simple_popup_info").each(function() {
//            $(this).css("display", "none").siblings(".simple_popup").click(function() {
//                $(".simple_popup_div").remove();
//                var strSimple = "<div class='simple_popup_div'><div class='simple_popup_inner'>";
//                strSimple += "<p class='simple_popup_close'>[ x ] <a href='#'>close</a></p>";
//                strSimple += $(this).siblings(".simple_popup_info").html();
//                strSimple += "</div></div>";
//                $("body").append(strSimple);
//                viewport.init(".simple_popup_div");
//                $(".simple_popup_close").click(function() {
//                    $(".simple_popup_div").remove();
//                    return false;
//                });
//                return false;
//            });
//        });
    $(".charmapDiv").each(function() {
        viewport.init(".charmapDiv");
        $(".simple_popup_close").click(function() {
            $(".charmapDiv").hide();
            return false;
        });
        return false;
    });
    $(".simple_popup").click(function() {
        $(".charmapDiv").show();
        return false;
    });
});
//function charit(name, value) {
function charit(value) {
//    document.forms['frmSearch'].elements[name].focus();
//    document.forms['frmSearch'].elements[name].value += value;
    if (selectedInput == null)  
        selectedInput = $("#txtQuery");
    selectedInput.val(selectedInput.val() + value);

    selectedInput.focus();
    // the trick is to set the value of the element after setting the cursor
    selectedInput.val(selectedInput.val());
    
    //alert(selectedInput.attr('id'));
    if (selectedInput.attr('id') == 'txtQuery')
        autoComplete(acSearchField.val());
}