var ns = document.layers ? true : false;
var ie = document.all && !window.opera ? true : false;;    // IEs
var dom = document.getElementById && !ie ? true : false;  // DOM-Browser

//Loadmodule
var loadingsequenz = "<table width='100%' height='100%' border='0' cellspacing='0' cellpadding='0'><tr><td align='center' valign='middle'><img src='images/loading.gif' /><br /></td></tr></table>";
var lastmodule = "";
var lastspalte = "";
var lastrichtung = "";
var lastoffset = "";
var lasid = "";
var activeflash = false;



function shop_start(){
	showGrayBox();
	
	new Ajax.Request('start.php', {
		method: 'get',	
		onSuccess: function(t) {
			$('gray_box_content').update(t.responseText);
			center('gray_box');
		},
		onFailure: function(t) {
			$('gray_box_content').update('Error ' + t.status + ' -- ' + t.statusText);
		},
		evalScript: true,
		asynchronous: true
		}
	);
}

function uebersichtRegister(id) {
	if($('kat'+id).style.display == 'none') {
		$('kat'+id).show();
		he = $('registertabelle_'+id).getHeight();
		$('kat'+id).hide();
		
		if(he > 150) $('kat'+id).style.height = (he-20)+'px';
		else $('kat'+id).style.height = '150px';
	}
	Effect.toggle('kat'+id,'blind');
}

function register(){
	new Ajax.Request('../ajax/register.php', {
		method: 'get',	
		onSuccess: function(t) {
			$('produkte').update(t.responseText);
		},
		onFailure: function(t) {
			$('produkte').update('Error ' + t.status + ' -- ' + t.statusText);
		},
		evalScript: true,
		asynchronous: true
		}
	);		
	resizeLayer('mainbody');
}

function profil(){
	new Ajax.Request('../ajax/profil.php', {
		method: 'get',	
		onSuccess: function(t) {
			$('produkte').update(t.responseText);
		},
		onFailure: function(t) {
			$('produkte').update('Error ' + t.status + ' -- ' + t.statusText);
		},
		evalScript: true,
		asynchronous: true
		}
	);		
	resizeLayer('mainbody');
}

function sendForm(action,id) {
	$('form_'+id+'_loading').show();
	//alert(sendForm.arguments[2]);
	if(sendForm.arguments.length>2) var dofunc="&dofunc="+sendForm.arguments[2];
	else var dofunc="";
	new Ajax.Request('../ajax/form_'+action+'.php?kat='+id+dofunc,
	{
		method: 'post',
		asynchronous: true,
		evalScript: true,
		postBody: $('form_'+id).serialize(),
		onComplete: function(t) {	
			$('form_'+id+'_response').update(t.responseText);
			$('form_'+id+'_loading').hide();
		},
		onFailure: function(t) {
			alert(t.status+' -- '+t.statusText);	
		}
	}
	);
}
function shopIndex(){
	document.location.href='shop.php';	
}
var unx1=0;
var unx2=4000;
function doNavigation(){
	/*if(typeof unx1 == "undefined"){
		var unx1=new Date().getTime()/1000;
		alert("reset");
	}
	var unx2=new Date().getTime()/1000;
	alert(unx2 + " - " +unx1);
	if(unx2-unx1 > 2000){
		unx1=unx2;*/
		new Ajax.Request('../ajax/navigation.php', {
			method: 'get',	
			onSuccess: function(t) {
				$('navi').update(t.responseText);
				doWK();
			},
			onFailure: function(t) {
				$('navi').update('Error ' + t.status + ' -- ' + t.statusText);
			},
			evalScript: true,
			asynchronous: true
			}
		);	
	
}


function logout(){
//	var best=window.confirm("Moechten Sie sich wirklich ausloggen?");
	if(window.confirm("Moechten Sie sich wirklich ausloggen?")){
		var pBody="&username=NIXDA";
		new Ajax.Request('../ajax/warenkorb.php',
		{
			method: 'post',
			postBody: pBody,
			asynchronous: true,
			evalScript: true,
			onComplete: function(t) {
			  // $('loading'+gid).hide();	
			   $('warenkorb').update(t.responseText);
			   location.reload();
			  // alert(t.responseText);
			},
			// Handle other errors
			onFailure: function(t) {
				alert('Error ' + t.status + ' -- ' + t.statusText);
			}		
		}
		);		
	}
}

function doWK(){
	var pBody="";
	new Ajax.Request('../ajax/warenkorb.php',
		{
			method: 'post',
			postBody: pBody,
			asynchronous: true,
			evalScript: true,
			onComplete: function(t) {
			  // $('loading'+gid).hide();	
			 //alert(t.responseText);
			  
			   $('warenkorb').update(t.responseText);
			  // alert(t.responseText);
			},
			// Handle other errors
			onFailure: function(t) {
				alert('Error ' + t.status + ' -- ' + t.statusText);
			}		
		}
		);			
}

function getSubNavi(topid){
	new Ajax.Request('../ajax/subnavigation.php?topid='+topid, {
		method: 'get',	
		onSuccess: function(t) {
			$('nav2').update(t.responseText);
		},
		onFailure: function(t) {
			$('produkte').update('Error ' + t.status + ' -- ' + t.statusText);
		},
		evalScript: true,
		asynchronous: true
		}
	);	
}

function changeTopId(topid){
	new Ajax.Request('../ajax/changetopid.php?topid='+topid, {
		method: 'get',	
		onSuccess: function(t) {
			return;
		},
		onFailure: function(t) {
			return;
		},
		evalScript: true,
		asynchronous: true
		}
	);
}

function getArt(gid){
	if(gid>0){
		var pBody=$('eigform'+gid).serialize();
		if($('eig2form'+gid)) pBody=pBody+"&"+$('eig2form'+gid).serialize();
		if($('eig3form'+gid)) pBody=pBody+"&"+$('eig3form'+gid).serialize();
		pBody=pBody+"&gid="+gid;
	}
	else var pBody="";
	new Ajax.Request('../ajax/eigenschaften2art.php',
	{
		method: 'post',
		postBody: pBody,
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {
		  // $('loading'+gid).hide();	
		   $('ajaxlayer').update(t.responseText);
		  // alert(t.responseText);
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);	
}

function login(){
	
	
	
	if($('username1')){
		var pBody="&username="+$('username1').value+"&passwort="+$('passwort1').value+"&dofunc="+add2wk.arguments[1];
		var typ="get";
	} else if($('username')){
		var pBody="&username="+$('username').value+"&passwort="+$('passwort').value;
		var typ="get";
	}else var pBody="";
	
	var typ='post';
	
	new Ajax.Request('../ajax/login.php'+(typ=='get'?'?1'+pBody:''),{
		method: typ,
		postBody: $("loginform").serialize(),
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {
		  // $('loading'+gid).hide();	
		   $('header_login').update(t.responseText);
		   //doNavigation();
		},
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);	
	
}

function add2wk(gid){
	
	if(gid > 0){
		var pBody = $('wkform'+gid).serialize()+"&gid="+gid;
		var typ   = 'post';
	} else if($('username1')){
		var pBody = "&username="+$('username1').value+"&passwort="+$('passwort1').value+"&dofunc="+add2wk.arguments[1];
		//var doNotTryToLogin = 1;
		var typ   = "post";
	} else if($('username')){
		var pBody = "&username="+$('username').value+"&passwort="+$('passwort').value;
		var typ   = "get";
	} else {
		var pBody = "";
	}
	
	new Ajax.Request('../ajax/warenkorb.php'+(typ=='get'?'?1'+pBody:''),{
		method: typ,
		postBody: pBody,
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {
		   $('warenkorb').update(t.responseText);
		   
		   //doNavigation();
		},
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);	
}

function pwVergessen() {
	$('gray_box_content').innerHTML = '<img src="images/loading_small2.gif" alt="" /><img src="images/loading_font.gif" alt="" />';
	new Ajax.Request('../module_gb/lostpw.php',
	{
		method: 'get',
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {	
		   $('gray_box_content').update(t.responseText);
		   center('gray_box');
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}

function checkLostPw() {
	$('lostpw_loading').show();
	new Ajax.Request('../ajax/lostpw.php',
	{
		method: 'post',
		postBody: $('lostpw_form').serialize(),
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {
		   $('lostpw_loading').hide();	
		   $('lostpw_result').update(t.responseText);
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}

function clearHeader(){
	/*
	$('headBild').src="../images/spacer.gif";
	$('head_title1').innerHTML="";
	$('head_title2').innerHTML="";
	
	//if(ie){
		$('head_informationen').innerHTML="";
	/*}
	else{
		
		//$('head_informationen').innerHTML="";
		var headli=$('head_informationen');
		if(headli){
			var hcc=headli.getElementsByTagName("tr");
		//alert(hcc.length);
		for(ir=0;ir<=hcc.length;ir++){
		//alert("doit");
		headli.deleteRow(-1);
		}
		}
		//$('headliste').innerHTML="";
		
	}*/
}
function headListe(elemente){
	//alert(elemente);
	var elemente=elemente.split(",");
	
	if($('head_informationen')){
			var htbl='<table border="0" cellspacing="0" cellpadding="0" width="350" id="headliste">';
			//var eigRow=new Array();
			for(i=0;i < elemente.length;i++){
				//alert(i);
				htbl+="<tr><th>&nbsp;</th><td>"+elemente[i]+"</td></tr>";
				/*var eigRow=$('headliste').insertRow(-1);
				var c1=document.createElement("th");
				c1.appendChild(document.createTextNode(" "));
				var c2=document.createElement("td");
				c2.appendChild(document.createTextNode(elemente[i]));
				eigRow.appendChild(c1);
				eigRow.appendChild(c2);
				$('headliste').appendChild(eigRow);*/
				
			}
			htbl+="</table>";
			$('head_informationen').innerHTML=htbl;
	}
			
	
}

function kategorie(kat){
	window.setTimeout("location.href='shop.php?kat="+kat+"';",50);	
}
var step;
function zeigeWarenkorb(step){
	if($('bestellform')) var pBody=$('bestellform').serialize();
	else var pBody="";
	//alert(pBody);
	//return true;
	new Ajax.Request('../ajax/warenkorb_liste.php?step='+step, {
		method: 'post',
		postBody: pBody,
		onSuccess: function(t) {
			$('produkte').update(t.responseText);
		},
		onFailure: function(t) {
			$('produkte').update('Error ' + t.status + ' -- ' + t.statusText);
		},
		evalScript: true,
		asynchronous: true
		}
	);	
	resizeLayer('mainbody');
}
function finder_result(){
	$('produktfinder_result').innerHTML="<br /><br /><center><img src='../images/loading.gif'></center>";
	new Ajax.Request('../ajax/produktfinder_result.php',
	{
		method: 'post',
		postBody: $('produktfindermaske').serialize(),
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {
		   $('produktfinder_result').update(t.responseText);
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}
function trim (zeichenkette) {
  return zeichenkette.replace (/^\s+/, '').replace (/\s+$/, '');
}
function produktfinder(){
	if(produktfinder.arguments.length > 0) {
		if(produktfinder.arguments.length > 1){
			var search_arts=produktfinder.arguments[1];
			produktfinder.arguments[0]="__ARTSEARCH__";
		}else var search_arts="";
		if(trim(produktfinder.arguments[0]).length<3) alert("Bitte geben Sie mindestens 3 Zeichen ein.");
		else{
		new Ajax.Request('../ajax/produktfinder.php?search='+produktfinder.arguments[0]+'&dlartikelnummer='+search_arts, {
			method: 'get',	
			onSuccess: function(t) {
				$('produkte').update(t.responseText);
				finder_result();
			},
			onFailure: function(t) {
				$('produkte').update('Error ' + t.status + ' -- ' + t.statusText);
			},
			evalScript: true,
			asynchronous: true
			}
		);	
		}
	} else {
		new Ajax.Request('../ajax/produktfinder.php', {
			method: 'get',	
			onSuccess: function(t) {
				$('produkte').update(t.responseText);
			},
			onFailure: function(t) {
				$('produkte').update('Error ' + t.status + ' -- ' + t.statusText);
			},
			evalScript: true,
			asynchronous: true
			}
		);	
	}
	
	resizeLayer('mainbody');
}

function produkte(kat,start){
	new Ajax.Request('../ajax/produkte.php?kat='+kat+'&start='+start, {
		method: 'get',	
		onSuccess: function(t) {
			$('produkte').update(t.responseText);
			doNavigation();
		},
		onFailure: function(t) {
			$('produkte').update('Error ' + t.status + ' -- ' + t.statusText);
		},
		evalScript: true,
		asynchronous: true
		}
	);	
	resizeLayer('mainbody');
}
function gallery(num,gid) {
	$('gallery'+gid).hide();
	$('loading'+gid).show();
	if(num) $('dspl_num'+gid).value=num;
	new Ajax.Request('../ajax/gallery.php',
	{
		method: 'post',
		postBody: $('galleryf'+gid).serialize(),
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {
			
		   $('loading'+gid).hide();	
		   $('gallery'+gid).update(t.responseText);
		   $('gallery'+gid).show();
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}
function detail(img,cur,total,gi){
	showGrayBox();
	new Ajax.Request('../ajax/gallery_detail.php?i='+img+'&cur='+cur+'&total='+total+'&gi='+gi,
	{
		method: 'get',
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {	
		   $('gray_box_content').update(t.responseText);
		   center('gray_box');
		   //window.setTimeout("",400);
		 //  detail_view=true;
		   window.setTimeout("center('gray_box');", 500);
		   window.setTimeout("center('gray_box');",1500);
		  window.setTimeout("center('gray_box');",2500);
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}

 /////////////////////////
 // Graybox Stuff Start //
/////////////////////////
function showGrayBox() {
	$('gray_box_content').innerHTML = '<img src="images/loading.gif" />';
	center('gray_box');
	$('gray_overlay').show(); 
	hideSelect();
}
function hideGrayBox2(){
    $('gray_box').hide();
    $('gray_overlay').hide();
	$('gray_overlay').style.width = '1px';
	$('gray_overlay').style.height = '1px';
	showSelect();
}
function hideGrayBox(){
    if(activeflash != false) {
		addEdit('flashdarstellung.php?id='+activeflash,'Flashdarstellung');
		activeflash = false;
	} else {
		$('gray_box').hide();
		$('gray_overlay').hide();
		$('gray_overlay').style.width = '1px';
		$('gray_overlay').style.height = '1px';
		showSelect();
		
		/*if(hideGrayBox.arguments.length > 0 && !ie) {
			includeModuleHidden(lastmodule,'../');
		} else {
			includeModuleHidden(lastmodule);
		}*/
	}
}

function center(element){
    try{
        element = $(element);
    }catch(e){
        return;
    }
	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
		
	if(ie) breite = arrayPageSize[0]+"px";
	else breite = "100%";
	
	$('gray_overlay').style.width = breite;
	$('gray_overlay').style.height = (arrayPageSize[1])+"px";
	
	//alert(window.document.body.offsetHeight + " - " + document.body.clientHeight + " - " + document.documentElement.clientHeight + " - " + window.innerHeight + " - " + document.documentElement.scrollTop);
    
	element.style.position = 'absolute';
    element.style.zIndex   = 99;

    var elementDimensions = Element.getDimensions(element);

	//alert(elementDimensions.width + " " + element +" " + elementDimensions.height);
	
	element.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - elementDimensions.height) / 2) + 'px');
	element.style.left = (((arrayPageSize[0] - 20 - elementDimensions.width) / 2) + 'px');

    element.style.display  = 'block';
	
	//alert(arrayPageSize[0] + " - " + arrayPageSize[1] + " - " + arrayPageSize[2] + " - " + arrayPageSize[3]);
	//alert(arrayPageScroll[0] + " - " + arrayPageScroll[1]);
}

function resizeLayer(element){
	try{
        element = $(element);
    }catch(e){
        return;
    }
	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	//element.style.position = 'absolute';
   // element.style.zIndex   = 99;

    var elementDimensions = Element.getDimensions(element);
	//alert(elementDimensions.width + " " + element +" " + elementDimensions.height);
	//element.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - elementDimensions.height) / 2) + 'px');
	element.style.height = Math.floor(arrayPageSize[1]-198)+'px'
	//alert(element.style.height );
    //element.style.display  = 'block';
}

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}


function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

//alert(pageHeight);
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function hideSelect() {
	selects = parent.document.getElementsByTagName( 'select' );
   	for ( i = 0; i != selects.length; i++ )
	{
		selects[i].style.visibility = 'hidden';
    }
}

function showSelect() {
	selects = parent.document.getElementsByTagName( 'select' );
    for ( i = 0; i != selects.length; i++ )
	{
		selects[i].style.visibility = 'visible';
	}
}

	function datenschutz(){
	window.open('datenschutz.php','datenschutz','width=800,height=500,scrollbars=yes');
}


/*
\\\\\\\\\\\\\\\\\\\\\\\\
 \\ Graybox Stuff ENDE \\
  \\\\\\\\\\\\\\\\\\\\\\\\
*/