function getCookie(Name,Default){
    var search = Name + "="
    if (document.cookie.length > 0){
        offset = document.cookie.indexOf(search)
        if (offset != -1){
            offset += search.length
            end = document.cookie.indexOf(";", offset)
            if (end == -1)
                end = document.cookie.length
            return unescape(document.cookie.substring(offset, end))
        }
    }
    return Default;
}

// automatische selektion in einem select element
function selectOption(element, value){
    var opt = element.options;
    for(i=0;i<opt.length;i++){
        if(opt[i].value==value){
            element.selectedIndex = i;
            return;
        }
    }
}

function selectRadio(form, fieldName, selectedValue){
    var field = form[fieldName];
    for(i=0;i<field.length;i++){
        if(field[i].value==selectedValue){
            field[i].checked=true;
            return;
        }
    }
}

function check(element, value){
    if(element.value == value)
        element.checked = true;
}
// division display or none ------------------------------------
function display(element,state){
    node = document.getElementById(element);
    if(node){
        node.style.display = state ? "" : "none";
    }
}

// division show hide ------------------------------------
var openDiv=null;
function showDiv(divId){
    if(openDiv!=null && openDiv!=divId)
        hideDiv(openDiv);
    div = document.getElementById(divId);
    div.style.visibility = 'visible';
    openDiv = divId;
}
function hideDiv(divId){
    div = document.getElementById(divId);
    div.style.visibility = 'hidden';
}

// confirm link
function confirmAction(href,prompt){
    if(confirm(prompt))
        window.location.href=href;
}

// confirm submission of form
function confirmSubmit(prompt){
    return confirm(prompt);
}

// fuegt zeichen in ein input field ein
// Bsp: <img onclick="insertTags(adresse.nachname, '[b]', '[/b]')" border="0" src="bold.png" title="Text als fett markieren">
function insertTags(input, aTag, eTag) {
  input.focus();
  /* für Internet Explorer */
  if(typeof document.selection != 'undefined') {
    /* Einfügen des Formatierungscodes */
    var range = document.selection.createRange();
    var insText = range.text;
    range.text = aTag + insText + eTag;
    /* Anpassen der Cursorposition */
    range = document.selection.createRange();
    if (insText.length == 0) {
      range.move('character', -eTag.length);
    } else {
      range.moveStart('character', aTag.length + insText.length + eTag.length);
    }
    range.select();
  }
  /* für neuere auf Gecko basierende Browser */
  else if(typeof input.selectionStart != 'undefined')
  {
    /* Einfügen des Formatierungscodes */
    var start = input.selectionStart;
    var end = input.selectionEnd;
    var insText = input.value.substring(start, end);
    input.value = input.value.substr(0, start) + aTag + insText + eTag + input.value.substr(end);
    /* Anpassen der Cursorposition */
    var pos;
    if (insText.length == 0) {
      pos = start + aTag.length;
    } else {
      pos = start + aTag.length + insText.length + eTag.length;
    }
    input.selectionStart = pos;
    input.selectionEnd = pos;
  }
}

function showDetails(id){
    var url = "http://"
             +"anwaltsuche.anwalt-suchservice.de"
             +"/anwaltsuche/standard/index.html"
             +"?method=detailsId&contactId="+id;
    window.open(url, "details");
}

function getDimension(element)
{
    var x = y = 0;
    var node = element;
    while (node) {
        x += node.offsetLeft;
        y += node.offsetTop;
        node = node.offsetParent;
    }

    var dimension=new Object();
    dimension.x=x;
    dimension.y=y;
    dimension.width  = element.offsetWidth;
    dimension.height = element.offsetHeight;
    return dimension;
}

function zentrieren(id)
{
    var element = document.getElementById(id);
    
    var dimBody    = getDimension(document.body);
    var dimElement = getDimension(element);
    
    element.style.top  = "" + (dimBody.height - dimElement.height)/2 + "px";
    element.style.left = "" + (dimBody.width  - dimElement.width)/2 + "px";
}
