function showTab(element, tab) {
    try {
	var parentElement = element.parentNode;
	if (parentElement.nodeType == 3) {
		parentElement = element.parentNode.parentNode;
	}
	var node = parentElement.firstChild;
	if (node.nodeType == 3) {
		node = node.nextSibling;
	}
	for (var i=0; i<parentElement.childNodes.length; i++) {
		if (node != null) {
			node.className = "";
			node = node.nextSibling;
		}
	}
	element.className = "selected";
	if (arguments.length == 3) {
	    var tab_ident = arguments[2];
	} else {
	    var tab_ident = 'tab_';
	}
	for (var i=1; i<120; i++) {
		try {
			document.getElementById(tab_ident + i).style.display = 'none';
		} catch(err) {}
	}
	document.getElementById(tab).style.display = '';

    } catch(globerr) {}
}

 
function showAllTabs() {
        for (var i=1; i<99; i++) {
                try {
                        document.getElementById('tab_' + i).style.display = '';
                } catch(err) {}
        }
}




/* switch visibility for two layers 
 * currently used for overloaded teasers 
 */

function switchVisibilityById(invisibleid,visibleid) {
    document.getElementById(invisibleid).style.display = 'none';
    document.getElementById(visibleid).style.display = '';
    return true;
}



/* automatical switching for the above thing  */

function pager_switcher(idlabel) {

    /* currently displayed teaser and teaser to be displayed after switching are stuffed in JS variables: */
    var this_current = eval('pager_' + idlabel + '_current');
    var this_next = eval('pager_' + idlabel + '_next');

    /*  call switcher function (cf. above) */
    switchVisibilityById('teaser_' + idlabel + '_' + this_current,'teaser_' + idlabel + '_' + this_next);

    /* reset JS variables
     *  complication for next-to-be-displayed teaser: 
     * is new current teaser the last in the teaser overload row? then set _first_ teaser als next one.
     */
    eval('pager_' + idlabel + '_current = this_next');
    if (this_next == eval('pager_' + idlabel + '_last')) eval('pager_' + idlabel + '_next = 1');
    else eval('pager_' + idlabel + '_next++');

    return;
}



function replace_ivw_tag() {
    newopts="";
    ajaxurl = js_ivw + "?r=" + escape(document.referrer) + "&amp;d=" + (Math.random()*100000);
    newAjaxRequest(); 
    newopts="";
    return true;
}

function replace_ivwpixel() {

    document.getElementById("ivwpixel").src = js_ivw + "?r=" + escape(document.referrer) + "&amp;d=" + (Math.random()*100000);
    return true;

}

/* The "Blob" is the small mouse over div appearing on top stories */
var blobLifetime;

// opens a new blob (and closes an old one, if present)
function openBlob( node, text ) {
  if( document.getElementById('blob') ) {
    closeBlob();
  }
  x = getPosition(node)[0] + 20;
  y = getPosition(node)[1] + 5;
  var blob = document.createElement("div");
  blob.setAttribute( "style", "top: "+y+"px; left: "+x+"px;" );
  blob.style.top = y+"px";
  blob.style.left = x+"px";
  blob.setAttribute( "id", "blob" );
  blob.appendChild( document.createTextNode( text ) );
  blob.setAttribute( "onmouseover", "window.clearTimeout(blobLifetime)" );
  blob.setAttribute( "onmouseout", "blobLifetime = window.setTimeout( 'closeBlob()', 1000 );" );
  document.getElementsByTagName("body")[0].appendChild(blob);
  blobLifetime = window.setTimeout( "closeBlob()", 4000 );
}

// closes the blob
function closeBlob() {
  if( document.getElementById('blob') ) {
    document.getElementById('blob').parentNode.removeChild(document.getElementById('blob'));
  }
}

// get x and y offset of an element
function getPosition( node ) {
  var x=0,y=0;
  var tempNode = node;
  do {
    x = x + tempNode.offsetLeft;
    y = y + tempNode.offsetTop;
    tempNode = tempNode.offsetParent;
  } while( tempNode.offsetParent );
  return new Array(x,y);
}


/* Content hiders */

// show the content of a .contentHider
function showContent( node ) {
  children = node.parentNode.childNodes;
  for( i = 0; i < children.length; i++ ) {
    if( children[i].nodeName.toLowerCase() == "div" ) {
      children[i].style.display = "block";
    }
  }
  node.getElementsByTagName("img")[0].setAttribute( "src", "/mat/contentVisible.gif" );
  node.onclick=function(){hideContent(this); };
}

// hide the content of a .contentHider
function hideContent( node ) {
  children = node.parentNode.childNodes;
  for( i = 0; i < children.length; i++ ) {
    if( children[i].nodeName.toLowerCase() == "div" ) {
      children[i].style.display = "none";
    }
  }
  node.getElementsByTagName("img")[0].setAttribute( "src", "/mat/contentHidden.gif" );
  node.onclick=function(){showContent(this); };
}


function blaetterkataloge_box(beilagenid) {
  var sel = document.getElementById (beilagenid);
  var opt = {};
  for (var i = 1; i < sel.options.length; i++) {
    if (sel.options[i].value == "") {
      sel.options[i].value = sel.options[i].text;
    }
    opt[sel.options[i].value] = sel.options[i].text;
  }
  var action = sel.form.action;

  var nsel = document.createElement ("div");
  var ul = document.createElement ("ul");
  var s = true;
  for (var p in opt) {
    var li = document.createElement ("li");
    li.appendChild (document.createTextNode (opt[p]));
    li.onclick = (function (a, p) {
      return function () {
        window.location.href = p;
      }
    })(action, p);
    if (s) {
      li.className = "odd";
    }
    s = !s;
    ul.appendChild (li);
  }

  var psel = document.createElement ("p");
  psel.className = "pseudoselect";
  var span = document.createElement ("span");
  span.appendChild (document.createTextNode (" Beilage w\u00e4hlen "));
  psel.appendChild (span);
  var button = document.createElement ("input");
  button.type = "image";
  button.src = "/mat/select.png";
  button.onclick = (function (id) {
    return function () {
      blaetterkataloge_unfold (id);
    };
  })(beilagenid);
  button.setAttribute ("id", "myselectbutton"+beilagenid);
  ul.setAttribute ("id", "myselect"+beilagenid);
  ul.className = "pseudoinput";
  psel.appendChild (button);
  sel.parentNode.insertBefore (psel, sel);
  sel.parentNode.replaceChild (ul, sel);
  button.form.onsubmit = function () { return false; };
}

function blaetterkataloge_unfold (id) {
  var u = document.getElementById ("myselect"+id);
  var b = document.getElementById ("myselectbutton"+id);
  if (!u.style.display || u.style.display == "none") {
    u.style.display = "block";
    //b.firstChild.nodeValue = "\u039B";
    b.src = "/mat/selected.png";
  } else {
    u.style.display = "none";
    //b.firstChild.nodeValue = "v";
    b.src = "/mat/select.png";
  }
  return false;
}



function Workspace_ShowAndHideLayer(layer_id, icon_id) {

    var l = document.getElementById(layer_id);
    if (icon_id != '') var icon = document.getElementById(icon_id);

    if (l.style.display == 'none') {
	l.style.display = ''; 
	
	if (icon_id != '') {
	    if (arguments[2]) icon.src = arguments[2];
	    else icon.src = '/mat/c-close.gif'; 
	}
    } else {
	l.style.display = 'none';
	if (icon_id != '') {
	    if (arguments[2]) icon.src = arguments[2];
	    else icon.src = '/mat/c-edit.gif'; 
	}
    }

    return true;

}




/*+*************************************************************************
 *                                                                         *
 *  F R O N T E N D   C L A S S                                              *
 *                                                                         *
 *  Many friendly helpers to make life easier in the frontend...            *
 *                                                                         *
 ***************************************************************************/

/**
 * initialize frontend class
 */
var frontend = {};



/*           F R O N T E N D   H T T P  A J A X         */


/**
 * initialize frontend http class
 */
frontend.http = {};


/**
 * AJAX Connection class
 */
frontend.http.Connection = function () {
  this.httpRequest = false;
  try {
    this.httpRequest = new XMLHttpRequest();
  }	catch (e) {
    try {
      this.httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        this.httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        this.httpRequest = false;
        return null;
      }
    }
  }

  this.connect = function (url, method, vars, callback) {
    if (!this.httpRequest) {
      return false;
    }
    method = method.toUpperCase();
    try {
      if (method == "GET") {
        this.httpRequest.open (method, url+(vars != ''? "?" + vars : ''), true);
        vars = null;
      } else {
        this.httpRequest.open (method, url, true);
        this.httpRequest.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
      }
      if (!callback) {
        callback = function (obj) {};
      }
      this.httpRequest.onreadystatechange = (function (obj) {
        return function () {
          if (obj.httpRequest.readyState == 4) {
            callback (obj.httpRequest);
          }
        }
      }) (this);
      this.httpRequest.send (vars);
    } catch(z) {
      return false;
    }
    return true;
  };
};


/**
 * send an "I'm alive" message back to the system
 */
frontend.http.ping = function (url, keepPinging) {
  var ping = new frontend.http.Connection ();
  if (ping) {
    ping.connect ("ajaxresponder.php", "post", "request=ping&url="+url, false);
    if (keepPinging) {
      frontend.http.pingTimeout = window.setTimeout (function () { frontend.http.ping (url, true); }, 30000);
    }
  }
}



/* delete one tick teaser */
frontend.http.delete_liveticker_tick = function (tick_id, ticker_id, user_id) {

    this.ticker_id = ticker_id;
    this.tick_id = tick_id;
    this.user_id = user_id;

    var connector = new frontend.http.Connection ();
    connector.connect ("/workspace/" + ticker_id + "-liveticker,1,0.html", "post", "f_delete_tick=" + tick_id + "&ajaxcall=true");

}

    
frontend.http.alter_liveticker_teaser_ticks = function (layer, ticker_id, ticker_status, number_of_teased_ticks) {
    var connector = new frontend.http.Connection ();
    this.layer = document.getElementById(layer);
    connector.connect ("/ajaxcalls/", "get", "mode=get_liveticker_ticks&object_id=" + ticker_id, frontend.http.print_response);
}

frontend.http.print_response = function (s) {
    frontend.http.layer.innerHTML=s.responseText;
}


frontend.http.get_wirkungsvoll_ad = function (layer) {
    var connector = new frontend.http.Connection ();
    this.layer = document.getElementById(layer);
    var currentDate = new Date();
    connector.connect ("/wirkungsvoll.php", "get", "myurl=" + escape(document.URL) + "&amp;t=" + currentDate.getTime(), frontend.http.print_response);
}



/*       E N D   F R O N T E N D   H T T P   A J A X      */


function addOnLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}



function load_soccer_frames (league_id) {
    document.getElementById('frametable').src = 'http://tippspiel.oberpfalznetz.de/soccer_table_frame.php?league=' + league_id;
    document.getElementById('frameresult').src = 'http://tippspiel.oberpfalznetz.de/soccer_result_frame.php?league=' + league_id;
    xxl_check = document.getElementById('xxlbanner');
    if (xxl_check) {
        xxl_anchor = xxl_check.lastChild;
        xxl_anchor_src = xxl_anchor.firstChild.src;
        xxl_anchor.firstChild.src = xxl_anchor_src;
    }
    sky_check = document.getElementById('skyscraper_extreme_right');
    if (sky_check) {
        sky_anchor = sky_check.firstChild.firstChild;
        sky_src = sky_anchor.firstChild.src;
        sky_anchor.firstChild.src = sky_src;
    }
}

