
/* - ogmskin_javascript.js - */
/*
 * Javascript for OGM Skin
 * -----------------------
 * Version  :   0.1
 * Author   :   t.hinze@positiv-multimedia.com
 * Date     :   23.5.2008
 *
 """ This Javascript contains all needed JS-functions.
 """
 */


function getNewRequest() {
    /* return a new XMLHttpRequest
    */
    var request = null;
    try {
        request = new XMLHttpRequest();
    } 
    catch (abc) {
        try {
            request = newActiveXObject("Msxml12.XMLHTTP");
        } 
        catch (xyz) {
            request = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    if (!request) {
        request = "XMLRequest creation failed";
    }
    return request;
}
//---------------------------


function showTooltip(ref, text) {
    /* create a tooltip near the mouse cursor
    */
    var tip = window.document.getElementById("Tooltip");
    if (tip) {
        tip.parentNode.removeChild(tip);
    }
    tip = window.document.createElement('DIV');
    /*
    tip.style.position    = 'absolute';
    tip.style.zIndex      = 200;
    // tip.style.left        = ref.offsetWidth + 'px';
    tip.style.marginTop   = '-3.5em';
    tip.style.padding     = '3px';
    tip.style.background  = '#FFFFC0';
    tip.style.border      = '1px solid #cc0000';
    */
    tip.style.marginLeft  = ref.offsetLeft + 'px';
    tip.id                = 'Tooltip';
    tip.innerHTML         = text;
    ref.parentNode.parentNode.appendChild(tip);
}
//---------------------------


function killTooltip() {
    /* remove the tooltip
    */
    var tip = window.document.getElementById("Tooltip");
    tip.parentNode.removeChild(tip);
}
//----------------------------


function printEntry(url) {
    /* print the current entry (visitcard)
    */
    var content = jq('#entry_view'); // document.getElementById("entry_view");
    if (content) {
        var html = jq(content).html();
        var popup = window.open(url, "Eintrag drucken", "menubar=no,status=no,toolbar=no,resizable=yes,width=775");
    }
    return false;
}
//---------------------------


function jumpToLetter(letter) {
    /* jump to the anchor named 'letter' + letter
    */
    var anchor = jq('#letter' + letter); 
    if (anchor) { 
        document.location.href = '#letter' + letter; 
    }
}
//---------------------------

function checkDistField(event) {
    var cityField = jq('#plz_city_field');
    var cityVal   = cityField.attr('value');
    if (cityVal) {
        jq('#dist_field').removeAttr('disabled');
    } else {
        jq('#dist_field').attr('disabled');
    }
}
/* registerPloneFunction(any_functionname); */

/* initialize the distance search field
*/
jq(document).ready( function () {
    jq('#searchbox_dist_field').css({display: 'block'});
    var cityField = jq('#plz_city_field');
    var cityVal   = cityField.attr('value');
    cityField.bind('change', checkDistField);
    // cityField.bind('click', checkDistField);
    if (cityVal) {
        jq('#dist_field').removeAttr('disabled');
    } else {
        jq('#dist_field').attr('disabled');
    }
});

