// Formularfelder Ã¼berprÃ¼fen
function chkMail() {
	var chkOK = true;
	var chkMail = true;
	var chkEmpty = true;
	var msg = "";

	$$(".chkEmpty").each( function(item){
		if($F(item)=="") {
			chkOK = false;
			chkEmpty = false;
			item.setStyle({backgroundColor: '#FF9999'});
		} else {
			item.setStyle({backgroundColor: '#FFFFFF'});
		}
	} );

	$$(".chkEmail").each( function(item){
                var reg = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)'+'(\\@)([a-zA-Z0-9\\-\\.]+)'+'(\\.)([a-zA-Z]{2,4})$');
                
		if(!reg.test($F(item)))	{
		//if($F(item)=="") {
			chkOK = false;
			chkMail = false;
			item.setStyle({backgroundColor: '#FF9999'});
		} else {
			item.setStyle({backgroundColor: '#FFFFFF'});
		}
	} );

	if(!chkEmpty) msg += "Bitte füllen Sie die rot hinterlegten Felder aus!\n";
	if(!chkMail) msg += "Bitte tragen Sie eine korrekte E-Mail-Adresse ein!\n";
	if(msg!="") alert(msg);
	return chkOK;
}

function mouseRollOver()
{
	$$('.rollOver').each(function (i)
	{
		i.observe('mouseover', function (e)
		{
			index = i.src.lastIndexOf('.');
			if (index > -1) {i.src = i.src.substring(0, index)+'.mo'+i.src.substring(index);}
		})

		i.observe('mouseout', function (e)
		{
			i.src = i.src.replace('.mo.', '.');
		})
	});
}

//**************************
//*** SPAMSCHUTZ ***  
//**************************


// UnCryptMailto() entschluesselt die Mail-Adresse, zu zuvor mit
// der PHP-Funktion encryptEmail() verschlüsselt wurde
// Anwendung:
/*
<?php $link="javascript:linkTo_UnCryptMailto('".encryptEmail("john@doe.de")."');"; ?>
<a href="<?php echo $link ?>">E-Mail an John Doe schreiben</a>
*/
 
// JS function for uncrypting spam-protected emails:
function UnCryptMailto(s) {	//
	var n=0;
	var r="";
	for(var i=0; i < s.length; i++) {
		n=s.charCodeAt(i);
		if (n>=8364) {n = 128;}
		r += String.fromCharCode(n-(1));
	}
	return r;
}

  // JS function for uncrypting spam-protected emails:
function linkTo_UnCryptMailto(s)	{	//
	location.href="mailto:"+UnCryptMailto(s);
}


// finder
function finder()
{
	var preLoadImg = new Image();
	preLoadImg.src = '/libImages/buttonFinderOpen.png';
	
	$$('.headline').each(function (v)
	{
		v.style.cursor = 'pointer';
		
		v.stopObserving('click');
		v.observe('click', function ()
		{
			$$('.files').each(function (v2) {v2.style.display = 'none'; v2.previous('.headline').down('img').src = '/libImages/buttonFinderClosed.png';});
			
			this.down('img').src = '/libImages/buttonFinderOpen.png';
			this.next('.files').style.display = ($browser == 'IE 6' || $browser == 'IE 7' ? 'block' : 'table-row');
			
			this.stopObserving('click');
			this.observe('click', function ()
			{
				this.next('.files').style.display = 'none';
				this.down('img').src = '/libImages/buttonFinderClosed.png';
				finder();
			});
		});
	});
}

function subCat()
{
	$$('.subCat').each(function (v)
	{
		v.style.backgroundImage = 'url(/libImages/buttonFinderClosed.png)';
		v.siblings('.productBlock').each(function (v2) {v2.hide();});
		v.observe('click', function (e)
		{
			if (this.style.backgroundImage == 'url(/libImages/buttonFinderClosed.png)') {this.style.backgroundImage = 'url(/libImages/buttonFinderOpen.png)';}
			else {this.style.backgroundImage = 'url(/libImages/buttonFinderClosed.png)';}
			this.siblings('.productBlock').each(function (v2) {v2.toggle();});
		});
	});
}

function subCatAll(gOpen)
{
	if (gOpen)
	{
		$$('.subCat').each(function (v)
		{
			v.style.backgroundImage = 'url(/libImages/buttonFinderOpen.png)';
			v.siblings('.productBlock').each(function (v2) {v2.show();});
		});
	}
	else
	{
		$$('.subCat').each(function (v)
		{
			v.style.backgroundImage = 'url(/libImages/buttonFinderClosed.png)';
			v.siblings('.productBlock').each(function (v2) {v2.hide();});
		});
	}
}

function correctDropDown()
{
	$$('.homeMenu ul li ul li').each(function (v2)
	{
		v2.observe('mouseover', function (e)
		{
			if (this.down('ul'))
			{
				var y = this.down('ul').cumulativeOffset();
				y = (' '+y).split(',');
				y = y[1];
				
				var clip = document.viewport.getHeight() - y - this.down('ul').getHeight();
				if (clip < 0)
				{
					this.down('ul').style.marginTop = clip+'px';
					this.stopObserving('mouseover');
				}
			}
		});
	});
}