//
//
// base
//
//

function getContentById(elementId) {
 var elementContent = "&nbsp;";
 try {
  elementContent = document.getElementById(elementId).innerHTML
 } catch (e) {
  // ignore
 }
 return elementContent;
}

function getElementsByAttribute(attr,val,container)
{
 container = container||document
 var all = container.all||container.getElementsByTagName('*')
 var arr = []
 for(var k=0;k<all.length;k++)
 if(all[k].getAttribute(attr) == val)
 arr[arr.length] = all[k]
 return arr
}

function getElementsByCondition(condition,container)
{
container = container||document
var all = container.all||container.getElementsByTagName('*')
var arr = []
for(var k=0;k<all.length;k++)
{
var elm = all[k]
if(condition(elm,k))
arr[arr.length] = elm
}
return arr
}

function highlight(e) {
  var myTarget;
        if (!e) var e = window.event;
        if (e.target) myTarget = e.target;
        else myTarget = e.srcElement;

  if(   myTarget.style.backgroundColor == "yellow" ) {
    myTarget.style.backgroundColor = "white";
  } else {
    myTarget.style.backgroundColor = "yellow";
  }
}


function getListings() {
  // var listings = getElementsByAttribute('class', 'noindent');
  var listings = getElementsByCondition(function(el){return el.className.indexOf('noindent')>-1});

  for ( var i=0; i<listings.length; i++ ){
    var myUl = listings[i];
    myUl.onmouseover = highlight;
    // myUl.setEvent("onmouseover", "highlight(this)");
  }
}

function merken (titleText) {
    if (window.sidebar) {
        window.sidebar.addPanel(titleText, window.location,"");
    } else if( window.external ) {
        window.external.AddFavorite( window.location, titleText); }
    else if(window.opera && window.print) {
        return true;
    }
}

//
//
// zippy
//
//

function _setEltDisplay(a,c){
	if(!document.getElementById){
		return false
	}
	var b=document.getElementById(a);
	if(b){
		b.style.display=c
	}
	return false;
}
function _toggleSection(a){
	var c=a.id.indexOf("_");
	if(c==-1){return false}
	var b="cp"+a.id.substring(c);
	if(a.name=="on"){
		_setEltDisplay(b,"");
		a.name="off";
	} else {
		_setEltDisplay(b,"none");
		a.name="on";
	}
	return false;
}

//
//
// zoom img
//
//

function zoom_img_mover(element) {
  element.className='zoom_img_big';
  if(navigator.appVersion.indexOf("MSIE")>-1) {
    element.style.cursor='hand';    
  } else {
    element.style.cursor='pointer';
  }
  return true;
}

function zoom_img_mout(element) {
  element.className='zoom_img_normal';
  element.style.cursor='default';
  return true;
}


function switchDiv(divOldId,divNewId) {
  divOld = document.getElementById(divOldId);
  divNew = document.getElementById(divNewId);
  divOld.style.display="none";
  divNew.style.display="inline";
}

//
//
// tooltip
//
//

/* see ../css/base.css -> tooltip*/
var tt = null;
var visible = false;
var xOffset = -80;
var yOffset = 20;

var mouseDownX = 0;
var mouseDownY = 0;

// param: event - the mouse event
// return: none
// global: set mouseDownX and mouseDownY
function showPosition(event) {
	if (window.event) {
		x = window.event.clientX;
		y = window.event.clientY;
	} else {
		x = event.clientX;
		y = event.clientY;
	}
	mouseDownX = x;
	mouseDownY = y;
}


// param: divName - name of surrounding of the tooltip div
// return: none
function toggleTtName(divName) {
	if(visible == true) {
		tt.style.display = "none";
		visible = false;
	} else {
		// get image inside tooltip (image is used to give the div a name :-/ )
		image = document.getElementsByName(divName)[1];
        if(typeof(image) == "undefined" || image == null) {
          image = document.getElementsByName(divName)[0];
        }

        // get tooltip
		tt = image.parentNode;
		
		tt.style.left = (mouseDownX + xOffset) + "px";
		tt.style.top 	= (mouseDownY + yOffset) + "px";		
		tt.style.display = "block";
		visible = true;
	}	
}

//
//
// click
//
//

/* use on a tr with smthing like: */
/* <tr class="normal" onclick="mclick(findChild(this, 'a'))"  ... */
/* to click the first anchor within the tr */

function findChild (element, nodeName) {
  return element.getElementsByTagName(nodeName)[0];
}

function mclick(anchor) {
  window.open(anchor.href,'new','width=1000,height=700,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes');
  return null;
}

function mclickSame(anchor) {
  window.location.href=anchor.href;
  return null;
}


function mover(element, statusText) {
  element.className='highlight';
  if(navigator.appVersion.indexOf("MSIE")>-1) {
    element.style.cursor='hand';    
  } else {
    element.style.cursor='pointer';
  }
  self.status=statusText;
  return true;
}

function mout(element) {
  element.className='normal';
  element.style.cursor='default';
  self.status='';
  return true;
}

function table_mclick(pos, par, tpl, col, row, kw, uip, ws) {
  table_img=new Image()
  table_img.src="track_table_click.jsp?pos=" + pos + "&par=" + par + "&tpl=" + tpl + "&col=" + col + "&row=" + row + "&kw=" + kw + "&uip=" + uip + "&ws=" + ws;
}

//
//
// google
//
//

var google_rc = {
  format: '180x150_rc',
  width: 180,
  height: 150,
  modules: ['news','searches'],
  color_line: 'B3C98C',
  color_link: '336633',
  color_bg: 'ffffff',
  color_text: '000000',
  color_source: '999999',
  color_header:  'EAFDC8',
  color_footer: 'EAFDC8'
};

//
//
// google maps
//
//

var map = null;
var custIcon = null;

function initMap(divId) {
 if (GBrowserIsCompatible()) {
  map = new GMap2(document.getElementById("mapDiv"));
  map.addControl(new GSmallMapControl());
  map.addControl(new GMapTypeControl());
  map.setCenter(new GLatLng(51.2, 11.0), 5);

  // Create a base icon for all of our markers that specifies the
  // shadow, icon dimensions, etc.
  var baseIcon = new GIcon();
  baseIcon.shadow = "http://www.mrkauf.de/m/img/shadow50.png";
  baseIcon.iconSize = new GSize(20, 34);
  baseIcon.shadowSize = new GSize(37, 34);
  baseIcon.iconAnchor = new GPoint(9, 34);
  baseIcon.infoWindowAnchor = new GPoint(9, 2);
  baseIcon.infoShadowAnchor = new GPoint(18, 25);
            
  custIcon = new GIcon(baseIcon);
  custIcon.image = "http://www.mrkauf.de/m/img/m_red.png";
 }
}

function addPoint(_lat, _lon, _articleDivData, _show) {
  var articleDivData = document.getElementById(_articleDivData);
  
  markerOptions = { icon:custIcon };
  
  var marker = new GMarker(new GLatLng(_lat, _lon), markerOptions);

  GEvent.addListener(marker, "mouseover", function() {
   marker.openInfoWindowHtml('<div style="width: 180px; padding-right: 10px">' + articleDivData.innerHTML + '<\/div>', {maxWidth: 100});
  });

  map.addOverlay(marker);
  if(_show) {
    marker.openInfoWindowHtml('<div style="width: 180px; padding-right: 10px">' + articleDivData.innerHTML + '<\/div>', {maxWidth: 100});
  }
}

//
//
// styles
//
//

function getPreRender() {
 var styleTxt = "<style type=\"text/css\"><!-- \n";
 styleTxt = styleTxt + " di" + "v.p" + "reRender ";
 styleTxt = styleTxt + " { ";
 styleTxt = styleTxt + "  top" + ":" + "-" + "100" + "00px; ";
 styleTxt = styleTxt + " z" + "-" + "index" + ":" + "-" + "10; ";
 styleTxt = styleTxt + "width" + ":" + "400" + "px;";
 styleTxt = styleTxt + "pos" + "ition" + ":" + "abs" + "olute;";
 styleTxt = styleTxt + " } ";
 styleTxt = styleTxt + "\n--></style>";
 return styleTxt;
}
