/*
 * Funktion zum Wechseln von Tabs 
 */ 
function tabSelMenu (tabId, tabActive, tabNum) {
  for(i=1; i<=tabNum; i++) {
    tabMenu = tabId+"_tbm"+i;
    tabMenu = document.getElementById(tabMenu);
    tabContent = tabId+"_tbc"+i;
    tabContent = document.getElementById(tabContent);

    if(tabActive==i) {
          tabMenu.className = 'tabActive';
          tabContent.style.display  = 'block';
        } else {
          tabMenu.className = '';
          tabContent.style.display  = 'none';
        }
  }
}

/* 
 * Dropdown Login Box Funktion zum Anzeigen der ... Loginbox
 */
function logindropeffect() {
    if (document.getElementById('loginpopmenu').style.display == 'none') {
        document.getElementById('loginpopmenu').style.display = '';
    } else {
        document.getElementById('loginpopmenu').style.display = 'none'
    }
}

/* 
 * 25.08.2011, Daniel Hirth
 * Nur etwas ausgeben wenn GET-Variable snet_debug gesetzt ist 
 */
function snetAlert(value) {
	if ( getParam('snet_debug') == '1' ) {
		alert (value);
	}
}

/* 
 * 25.08.2011, Daniel Hirth
 * Nur etwas ausgeben wenn GET-Variable snet_debug gesetzt ist 
 */
function snetVarDump(element, limit, depth) {
	if ( getParam('snet_debug') == '1' ) {
		var_dump(element, limit, depth);
	}
}

/*
 * 25.08.2011, Daniel Hirth
 * Get-Parameter in Javascript ermitteln 
 */
function getParam(name) {
  name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
  var regexS = "[\\?&]" + name + "=([^&#]*)";
  var regex = new RegExp(regexS);
  var results = regex.exec(window.location.href);
  if(results == null)
    return "";
  else
    return decodeURIComponent(results[1].replace(/\+/g, " "));
}


/* 
 * 25.08.2011, Daniel Hirth
 * Var-Dump Popup für JS-Arrays und Objekte 
 */
function var_dump(element, limit, depth) {
	depth =	depth?depth:0;
	limit = limit?limit:1;

	returnString = '<ol>';

	for(property in element)
	{
		//Property domConfig isn't accessable
		if (property != 'domConfig')
		{
			returnString += '<li><strong>'+ property + '</strong> <small>(' + (typeof element[property]) +')</small>';

			if (typeof element[property] == 'number' || typeof element[property] == 'boolean')
				returnString += ' : <em>' + element[property] + '</em>';
			if (typeof element[property] == 'string' && element[property])
				returnString += ': <div style="background:#C9C9C9;border:1px solid black; overflow:auto;"><code>' +
									element[property].replace(/</g, '&amp;lt;').replace(/>/g, '&amp;gt;') + '</code></div>';

			if ((typeof element[property] == 'object') && (depth < limit))
				returnString += var_dump(element[property], limit, (depth + 1));

			returnString += '</li>';
		}
	}
	returnString += '</ol>';

	if(depth == 0)
	{
		winpop = window.open("", "","width=800,height=600,scrollbars,resizable");
		winpop.document.write('<pre>'+returnString+ '</pre>');
		winpop.document.close();
	}	

	return returnString;
}

/*
 * 25.08.2011, Daniel Hirth
 * Eine Javascript-Datei innerhalb des Javascripts includen
 */
function loadScript(url, callback)
{
    // adding the script tag to the head as suggested before
   var head= document.getElementsByTagName('head')[0];
   var script= document.createElement('script');
   script.type= 'text/javascript';
   script.src= url;

   // then bind the event to the callback function 
   // there are several events for cross browser compatibility
   script.onreadystatechange = callback;
   script.onload = callback

   // fire the loading
   head.appendChild(script);
}



/*
 * 21.11.2011 Daniel Hirth
 * Asynchrones Nachladen von IVW-Pixel
 * https://www.infonline.de/downloads/9-1356-493/INFOnline_Ajaxmessung.pdf 
 */
function ReloadPixelImages(PixelCode, PixelComment){ 
	if (typeof(PixelCode)=="string") {
		var Code = PixelCode; 
		var Comment = PixelComment; 
		var IVW="http://[angebotskennung].ivwbox.de/cgi-bin/ivw/[TYPE]/" + Code + ";";
		if (typeof(Comment)=="string") {
			IVW = IVW + Comment;
		}
		document.szmcounter.src =  IVW+"?r="+escape(document.referrer)+"&d=" 
		+(Math.random()*100000);
	}
} 
