/*
Copyright 2008 by Indygfx.de

Javascript zur Weitergabe und kommerziellen Nutzung ausschließlich in Verbindung mit der Firmendatenbanksuche der MHWK e.V.
http://www.mhwk.de
*/


function createIframe()
{
if (checkForFrames())
  createPopUp();
else
  createLayer();
  
}

function checkForLoos()
{
if (navigator.userAgent.indexOf('MSIE')>=0 && document.compatMode.indexOf('CSS')<0)
	{
	return false; 
	}
return true;
}



function checkForFrames() // prueft auf Framestruktur
{
if (parent.frames.length > 1 )
	return true;
else if (checkForLoos())
   return false;
else return true;
}


/* Fuer Seiten ohne Framestruktur */

var mhwk_od = null;
var mhwk_d = null;
var mhwk_f = null;
var NewWindow=null;




function getFormContent(obj)
{
var res='?indy=action&query_p=alle';
if (obj)
	{
	if (obj.query_f.value != '' && obj.query_f.value != obj.query_f.defaultValue)
	 	res = res + '&query_f='+obj.query_f.value;
	if (obj.stich.value != '' && obj.stich.value != obj.stich.defaultValue )
	 	res = res + '&stich='+obj.stich.value;	 	
	return res;
	}
else
	return null;
}

function findFormular(){
if (document.mhwk_form) 
	{
	return mhwk=document.mhwk_form;
	}
else if (document.getElementById('mhwk_form'))
	{
	return mhwk=document.getElementById('mhwk_form');
	}
else
  return null;
}


function createLayer()
{
//**** Formular finden
mhwk=findFormular();
//**** Ende Formular finden



//*** Bildschirmdimensionen ermitteln
if (window.innerWidth){	
	var swidth=window.innerWidth;
 	var sheight=window.innerHeight;
 	}
 else if (document.documentElement.clientWidth){	
	var swidth=document.documentElement.clientWidth;
 	var sheight=document.documentElement.clientHeight;
 	}
 else
 	{
 	var swidth=screen.availWidth;
 	var sheight=screen.availHeight; 	
 	}

if (swidth>870){
var boxHeight=500; // Breite des eigentlichen IFrames
var boxWidth=873; // Hoehe des eigentlichen IFrames
}
else // falls aufloesung kleiner als 870 x 400
{
var boxHeight=sheight-40; // Breite des eigentlichen IFrames
var boxWidth=swidth-40; // Hoehe des eigentlichen IFrames
}


var leftFree=swidth/2 - boxWidth/2;
var topFree=sheight/2 - (boxHeight+25)/2 ;

//*** Ende Bildschirmdimensionen ermitteln



//********** Aeusseres Div per DOM erstellen 
mhwk_od = document.createElement("div");
mhwk_od.setAttribute("id", 'MHWK_outer');
mhwk_od.setAttribute("name", 'MHWK_outer');
mhwk_od.style.position='fixed';
mhwk_od.style.left='0px';
mhwk_od.style.top='0px';
mhwk_od.style.border='0px';
mhwk_od.style.zIndex='1001';
mhwk_od.style.backgroundColor='#000';
mhwk_od.style.opacity='0.8';
mhwk_od.style.filter='alpha(opacity=80)';
mhwk_od.innerHTML='&nbsp;&nbsp;';
mhwk_od.style.height=sheight+'px';
mhwk_od.style.width=swidth+'px';

//**** ENDE aeusseres per DOM Div


//**** inneres Div per DOM erstellen
mhwk_d = document.createElement("div");
mhwk_d.setAttribute("id", 'MHWK_inner');
mhwk_d.setAttribute("name", 'MHWK_inner');
mhwk_d.style.zIndex='1002';
mhwk_d.style.position='absolute';
mhwk_d.style.textAlign='right';
mhwk_d.style.height=(boxHeight+25)+'px';
mhwk_d.style.width=boxWidth+'px';
mhwk_d.style.left=leftFree+'px';
mhwk_d.style.top=topFree+'px';
mhwk_d.style.position='fixed';

//**** Ende inneres Div per DOM erstellen


// **** Iframe per DOM erstellen
mhwk_f = document.createElement("iframe");
mhwk_f.setAttribute("id", 'MHWK_iframe');
mhwk_f.setAttribute("name", 'MHWK_iframe');
mhwk_f.setAttribute("frameborder", 0);
mhwk_f.setAttribute("width", boxWidth);
mhwk_f.setAttribute("height", boxHeight);
mhwk_f.style.backgroundColor='#ffffff';
mhwk_f.src='http://www.mhwk.de/fdb_extern/firmendatenbank_indy.php'+getFormContent(mhwk);
// **** Ende Iframe per DOM erstellen





//**** Link zum Schliessen des Iframes erstellen
var mhwk_close = document.createElement("a");
 mhwk_close.setAttribute("href", 'javascript:closeIframe();');
 mhwk_close.setAttribute("id", 'active');
 mhwk_close.style.float='right';

var	mhwk_close_text=document.createTextNode('close');
 	mhwk_close.appendChild(mhwk_close_text);

//**** Ende Link zum Schliessen des Iframes erstellen


//**** neue Elemente in Document einbinden

mhwk_d.appendChild(mhwk_close);
mhwk_d.appendChild(mhwk_f);
document.body.appendChild(mhwk_od);
document.body.appendChild(mhwk_d)

var aiframe=document.getElementById('MHWK_iframe');
if (aiframe)
	aiframe.frameborder='0';
//**** Ende neue Elemente in Document einbinden

}

function closeIframe()
{
if (mhwk_od && mhwk_d && mhwk_f)
	{
	mhwk_d.removeChild(mhwk_f);
	mhwk_d.parentNode.removeChild(mhwk_d);
	mhwk_od.parentNode.removeChild(mhwk_od);	
	}
}


/* ab hier fuer Frames */
//********************************************************************************************



function createPopUp(){

var notExists=false;

if (NewWindow && typeof(NewWindow.focus)=='function') 
{
NewWindow.focus();

}
else if(window.mhwkSearchPop && typeof(window.mhwkSearchPop.focus)=='function')
{
window.mhwkSearchPop.focus();
	
}
else
{
notExists=true; 
}

    if (notExists && findFormular())
	{
	 url='http://www.mhwk.de/fdb_extern/firmendatenbank_indy.php'+getFormContent(findFormular());

    NewWindow=window.open   (url,'mhwkSearchPop','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=870,height=500');
	}
}




