var http_request = false;

function macheRequest(url) {

      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/plain');
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            return false;
        }
        //http_request.onreadystatechange = alertInhalt;
        http_request.open('GET', url, true);
        http_request.send(null);
}
function setchar(letter) {document.forms['suchboxform'].suchwert.value += letter;document.forms['suchboxform'].elements['suchwert'].focus();}
function alertInhalt() {if (http_request.readyState == 4) {if (http_request.status == 200) {} else {}}}

function onw(url) {
 NeuesFenster =
 window.open(url, 'industrystock', 'width=800,height=600,left=60,top=40,scrollbars=yes,dependent=yes,resizable=yes');
 NeuesFenster.focus();
}
function onw_forwww(url) {
 NeuesFenster =
 window.open(url, 'industrystock_forward', 'width=1000,height=700,left=10,top=10,scrollbars=yes,dependent=yes,resizable=yes');
 NeuesFenster.focus();
}
function onwindow(url) {
 NeuesFenster =
 window.open(url, 'industrystock_advert');
 NeuesFenster.focus();
}
function homewechsel() {document.form2lang.submit();}
function businesswechsel(url) {
 document.myform.action='business-searched-'+url+'.html';
 document.myform.submit();
}
function industrywechsel(url) {
 document.myform.action='industry-searched-'+url+'.html';
 document.myform.submit();
}
function chinawechsel(url) {
 document.myform.action='china-searched-'+url+'.html';
 document.myform.submit();
}
function openwindow(url) {
 NeuesFenster =
 window.open('china-merke-'+url+'.html', 'merke', 'width=350,height=200,left=200,top=200,scrollbars=yes,dependent=yes,resizable=yes');
 NeuesFenster.focus();
}
function onwphoto(url) {
 NeuesFenster =
 window.open(url, 'industrystock_photo', 'width=600,height=400,left=60,top=40,scrollbars=yes,dependent=yes,resizable=yes');
 NeuesFenster.focus();
}
function alle(anzahl) {
for(var i = 0; i <= anzahl; i++)
 {
  document.forms[0].elements[i].checked=true;
 }
}
function alleprodukt(anzahl) {
for(var i = 0; i <= anzahl; i++)
 {
  document.mailform.elements[i].checked=true;
 }
}
function onw1(url) {
 NeuesFenster =
 window.open(url, 'produktbild', 'width=600,height=480,left=60,top=40,scrollbars=yes,dependent=yes,resizable=yes');
 NeuesFenster.focus();
}
function produktabsenden(url) {
 document.insertf.action='product-insertnow-'+url+'.html';
 document.insertf.submit();
}
function produktabsendenb(url) {
 document.insertf.action='product-insertb3-'+url+'.html';
 document.insertf.submit();
}
function checkUncheckAll(theElement) {
     var theForm = theElement.form, z = 0;
	 for(z=0; z<theForm.length;z++){
      if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){
	  theForm[z].checked = theElement.checked;
	  }
     }
    }
function getObj(obj)
{
   if (document.layers)
         return document.layers[obj];
   else if(document.getElementById)
         return document.getElementById(obj);
   else if(document.all)
         return document.all[obj];
   else
         return null;
}	
function showkontakt(infoname,lang) {
   var layer = getObj('con_'+infoname);
   if(!layer);
   if (document.layers) layer.display = "block";
   else layer.style.display = "block";
   
   var layer = getObj('conlink_'+infoname);
   if(!layer);
   if (document.layers) layer.display = "none";
   else layer.style.display = "none";
   macheRequest("/zaehle.php?getid="+infoname+"&lang="+lang);
}	
function showallkontakt(st,lang) {
 var holeids = st.split("-");
 for(var x=0; x <= holeids.length; x++)
 {
	if(holeids[x]>0)
	{
		var layer = getObj('con_'+holeids[x]);
		if(layer);
		{
			if (document.layers) layer.display = "block";
			else layer.style.display = "block";
		}
   
		var layer = getObj('conlink_'+holeids[x]);
		if(layer)
		{
			if (document.layers) layer.display = "none";
			else layer.style.display = "none";
			macheRequest("/zaehle.php?getid="+holeids[x]+"&lang="+lang);
		}
	}
 }
}
function showinfo(infoname) {
  document.getElementById(infoname).style.visibility = "visible";
  document.getElementById(infoname).style.display = "block";
}
function showinfohere(infoname) {
  if(document.getElementById(infoname).style.display == "block"){document.getElementById(infoname).style.display="none";}
  else {document.getElementById(infoname).style.display="block";}
}
function hideinfo(infoname) {
 document.getElementById(infoname).style.visibility = "hidden";
 document.getElementById(infoname).style.display="none";
}

function addLoadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

}
function ladebalken()
{
	var objLadebalken = document.getElementById('ladebalken');
	var objgreylayer = document.getElementById('greylayer');
	if(objgreylayer.style.display == 'block')
	{
		selects = document.getElementsByTagName("select");
				for (i = 0; i != selects.length; i++) {
					selects[i].style.visibility = "visible";
				}
		objgreylayer.style.display = 'none';
		objLadebalken.style.display = 'none';
	}
	else
	{
		var arrayPageSize = getPageSize();
		var arrayPageScroll = getPageScroll();
		var Top = (arrayPageScroll[1] + 30);
		var Left = ((arrayPageSize[0] - 20 - 100) / 2);
		objLadebalken.style.top = (Top < 0) ? "0px" : Top + "px";
		objLadebalken.style.left = (Left < 0) ? "0px" : Left + "px";
		objLadebalken.style.width = 100 + 'px';
		objLadebalken.style.height = 100 + 'px';	
		selects = document.getElementsByTagName("select");
				for (i = 0; i != selects.length; i++) {
					selects[i].style.visibility = "hidden";
				}
		objgreylayer.style.display = 'block';
		objLadebalken.style.display = 'block';
	}
}

function zeige_inhalt_in_fenster(response) {
    if(document.getElementById('profilbox') && document.getElementById('skyscraperdiv') &&
	document.getElementById('profilboxDetails') && document.getElementById('greylayer') && document.getElementById('ladebalken')){
        // prep objects
		var objProfilbox = document.getElementById('profilbox');
		var objSkyscraperdiv = document.getElementById('skyscraperdiv');
		var objProfilboxDetails = document.getElementById('profilboxDetails');
		var objgreylayer = document.getElementById('greylayer');
		var objladebalken = document.getElementById('ladebalken');
		var arrayPageSize = getPageSize();
		var arrayPageScroll = getPageScroll();
		// center profilbox  and make sure that the top and left values are not negative
		// and the content  placed outside the viewport
		var profilboxTop = (arrayPageScroll[1] + 30);
		var profilboxLeft = ((arrayPageSize[0] - 20 - 700) / 2);
		objProfilbox.style.top = (profilboxTop < 0) ? "0px" : profilboxTop + "px";
		objProfilbox.style.left = (profilboxLeft < 0) ? "0px" : profilboxLeft + "px";
		objProfilboxDetails.style.width = 700 + 'px';
		objProfilboxDetails.style.height = 500 + 'px';
		objProfilboxDetails.style.overflow = 'auto';
		
			// Hide select boxes as they will 'peek' through the image in IE
			selects = document.getElementsByTagName("select");
			for (i = 0; i != selects.length; i++) {
					selects[i].style.visibility = "hidden";
			}
		
		objProfilboxDetails.innerHTML = response;
		// A small pause between the image loading and displaying is required with IE,
			// this prevents the previous image displaying for a short burst causing flicker.
			if (navigator.appVersion.indexOf("MSIE")!=-1){
				pause(250);
			} 
	
		
		//objProfilbox.style.display = 'block';
		objSkyscraperdiv.style.display = 'none';
		objgreylayer.style.display = 'block';
		$("#profilbox").show("slow");
		// After image is loaded, update the overlay height as the new image might have
		// increased the overall page height.
		arrayPageSize = getPageSize();	
    }
}


// usage: format_zahl( number [, number]  [, bool]  )

function formatZahl(zahl, k, fix)

{

    if(!k) k = 0;

    var neu = '';

    // Runden

    var f = Math.pow(10, k);

    zahl = '' + parseInt( zahl * f + (.5 * (zahl > 0 ? 1 : -1)) ) / f ;

    // Komma ermittlen

    var idx = zahl.indexOf('.');

    // fehlende Nullen einf?gen

    if(fix)

    {

         zahl += (idx == -1 ? '.' : '' )

         + f.toString().substring(1);

    }

    // Nachkommastellen ermittlen

    idx = zahl.indexOf('.');

    if( idx == -1) idx = zahl.length;

    else neu = ',' + zahl.substr(idx + 1, k);

 

    // Tausendertrennzeichen

    while(idx > 0)

    {

        if(idx - 3 > 0)

        neu = '.' + zahl.substring( idx - 3, idx) + neu;

        else

        neu = zahl.substring(0, idx) + neu;

        idx -= 3;

    }

    return neu;

}
function setSuchformFocus(){
	var Obj = getObj('suchwerttopfeld');
	if(!Obj);else Obj.focus();
}
String.prototype.replaceAll  = function(s1,s2){   
    return this.replace(new RegExp(s1,"g"),s2);   
}
function addTradekeyAdvertisement(disc,domain,tag1,tag2,tag3,tag4) {
	var Tradekeyurl = "http://"+domain+".tradekey.com/ks-";

	var advertisementContent = disc + ": ";

	if (tag1 != '') {

		advertisementContent += "<br /><br /><a href='"  + Tradekeyurl + tag1.replaceAll(' ','-').toLowerCase() + "/'>" + tag1 + "</a> ";

	}

	if (tag2 != '') {

		advertisementContent += "<br /><br /><a href='"  + Tradekeyurl + tag2.replaceAll(' ','-').toLowerCase() + "/'>" + tag2 + "</a> ";

	}

	if (tag3 != '') {

		advertisementContent += "<br /><br /><a href='"  + Tradekeyurl + tag3.replaceAll(' ','-').toLowerCase() + "/'>" + tag3 + "</a> ";

	}

	if (tag4 != '') {

		advertisementContent += "<br /><br /><a href='"  + Tradekeyurl + tag4.replaceAll(' ','-').toLowerCase() + "/'>" + tag4 + "</a> ";

	}

	

	if (document.getElementById('addTradekeyAdvertisement_div') != null) {

		document.getElementById('addTradekeyAdvertisement_div').innerHTML = advertisementContent;

	}
	



}

