function set_cookie(name,value,tage) {
	if (tage) {
		var date = new Date();
		date.setTime(date.getTime()+(tage*24*60*60*1000));
		var expires = ";expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function get_cookie(n) {
	var name = n + "=";
	var cookies = document.cookie.split(';');
	for(var i=0;i < cookies.length;i++) {
		var ck = cookies[i];
		while (ck.charAt(0)==' ') ck = ck.substring(1,ck.length);
		if (ck.indexOf(name) == 0) return ck.substring(name.length,ck.length);
	}
	return null;
}

function pruefen(){	
	s_cookie = get_cookie('rm');
	if(s_cookie){
		document.myform.submit();
	}
	else{	
		openLightbox('/fileadmin/templates/BDO/lightbox/reifenmanager_lightbox.html');	
	}
}
/*
function check(){
	if(document.schluesselnr.hsn.value.length == 0 || document.schluesselnr.tsn.value.length == 0 ){
		alert (unescape("Bitte alle Felder ausf%FCllen"));
	    return false;
	}
	s_cookie = get_cookie('rm');
	if(s_cookie){
		tx_bdodropdown_pi1sucheTSN(document.schluesselnr.hsn.value,document.schluesselnr.tsn.value);
		return false;
	}	
	else {
		openLightbox('/fileadmin/templates/BDO/lightbox/reifenmanager_lightbox_tsn.html');
		return false;
	}
}
*/

 function pruefeTSN(val){
	            		if(val==1){
	            			alert (unescape("Es wurden keine passenden Eintr%E4ge gefunden."));
	            			return false;
	            		}
	            		else{
	            			s_cookie = get_cookie('rm');
	            			if(s_cookie){
	            				document.schluesselnr.submit();
	            			}
	            			else {
								openLightbox('/fileadmin/templates/BDO/lightbox/reifenmanager_lightbox_tsn.html');								
							}	
	            		}
 }	 



/* ==================================================================================================== */
/* Defaulteinstellungen 
 * k?nnen auf der jeweiligen Seite ?berschrieben werden, wenn die Variable
 * gesetzt wird, bevor das Script eingebunden wird
 */

var lightboxOverlayColor = lightboxOverlayColor ? lightboxOverlayColor : '000000';
var lightboxOverlayAlpha = lightboxOverlayAlpha ? lightboxOverlayAlpha : 50;
var lightboxMarginTop = lightboxMarginTop ? lightboxMarginTop : 200;
/* ==================================================================================================== */
/* User-Funktionen * /

/**
  * ?ffnet die Lightbox
  * wird normalerweise vom Script automatisch an alle URLs angeh?ngt die das Attribut  rel="fid_lightbox"  haben.
  * kann aber auch mannuell gerufen werden (z.B. aus einem Flash heraus)
  */
function openLightbox (url) {
	if (LightboxIsCurrentlyOpen) {
		closeLightbox();
	}
	else{
	    var flash = document.getElementsByClassName("tx-rbflashobject-pi1-swf_altcontent"); 
		for(i=0; i<flash.length;i++){
		 	document.getElementsByClassName("tx-rbflashobject-pi1-swf_altcontent")[i].style.visibility = "hidden";
		 	
		}
		if (document.all && !window.XMLHttpRequest) {
		 
		 var sel = document.getElementsByTagName("select");
		 for(i=0; i<sel.length;i++){
		 	document.getElementsByTagName("select")[i].style.visibility = "hidden";
		 	
		 }
		 
		}
		
	}	
	new Ajax.Updater('lightboxContent', url, {method: 'get', evalScripts: true,
        onComplete: function(){
            lightboxContentGeladen();
        }
	});

}

/**
  * Schlie?t die Lightbox
  */
function closeLightbox () {
	var bg = $('lightboxBG');
	var lb = $('lightbox');
	var lbc = $('lightboxContent');
	lb.hide();
	bg.hide();
	lbc.style.position = 'absolute';
	lbc.style.width = 'auto';
	lbc.innerHTML = '';
	LightboxIsCurrentlyOpen = false;
	var flash = document.getElementsByClassName("tx-rbflashobject-pi1-swf_altcontent");
	for(i=0; i<flash.length;i++){
	 	document.getElementsByClassName("tx-rbflashobject-pi1-swf_altcontent")[i].style.visibility = "visible";
		 	
	}	
	if (document.all && !window.XMLHttpRequest) {
		 
		 
		 var sel = document.getElementsByTagName("select");
		 for( var i=0;i<sel.length;i++){
		 	document.getElementsByTagName("select")[i].style.visibility = "visible";
		 	
		 }
		
	}
}


/* ==================================================================================================== */
/* ==================================================================================================== */




var LightboxIsCurrentlyOpen = false;

function initLightBox () {
	appendLightbox();
	document.observe('click', function(event) {
		var target = event.findElement('a[rel^=fid_lightbox]') || event.findElement('area[rel^=fid_lightbox]');
		if (target) {
			event.stop();			
			openLightbox(target.href);
			
		}
	});
}

function lightboxContentGeladen () {
	LightboxIsCurrentlyOpen = true;
	var bg = $('lightboxBG');
	var lb = $('lightbox');
	lb.show();
	bg.show();
	setLightboxSize();
}

function setLightboxSize () {
	var s_offset=document.body.cumulativeScrollOffset();
	//lightboxMarginTop=50;
	var bg = $('lightboxBG');
	var lb = $('lightbox');
	//lb.style.top=lightboxMarginTop+'px';	
	var lbc = $('lightboxContent');
	bg.style.height = '100%';
	var h = Math.max(Math.max(document.viewport.getHeight(), document.body.getHeight()), bg.getHeight());
	lbc.hide();
	lbc.style.width = lbc.getWidth()+'px';
	lbc.style.position = 'relative';
	
	if (lightboxCheckQuirks()) {
		if (lightboxCheckIE()) {
			var w = Math.max(document.viewport.getWidth(), document.body.getWidth());
			lbc.style.left = ((w - lbc.getWidth())/2) + 'px';
			bg.style.height = h+'px';
		}
	} else {
		bg.style.height = h+'px';
	}
	
	lbc.show();
}

function lightboxCheckIE () {
	if (document.all && !window.XMLHttpRequest) {
		return true;	// IE6
	} else if (document.all && !window.opera) {
		return true;	// IE7
	} else {
		return false;
	}
}

function lightboxCheckQuirks () {
	return (document.compatMode && document.compatMode=='BackCompat') ? true : false;
} 
	
/* h?ngt den Lightbox-Container im Body an */

function appendLightbox () {
	
	var code = '<div id="lightboxBG" style="display:none; position:absolute; top:0; left:0; width:100%; z-index:1000; background:#'+lightboxOverlayColor+'; filter:Alpha(opacity='+lightboxOverlayAlpha+'); opacity:'+(lightboxOverlayAlpha/100)+';"></div>';
	if (!window.XMLHttpRequest) {		
		code += '<div id="lightbox" style="position:absolute; top: expression(eval(document.documentElement.scrollTop + '+lightboxMarginTop+')+\'px\'); width:100%; z-index:1001; background:transparent;">';	
	}
	else{
		code += '<div id="lightbox" style="position:fixed; top:'+lightboxMarginTop+'px; width:100%; z-index:1001; background:transparent;">';
	}
	code += '<div id="lightboxContent" style="margin:0 auto;"></div></div>';	

	var objBody = $$('body')[0];
	objBody.insert(code);

	$('lightboxBG').observe('click', function() {closeLightbox(); });
	$('lightbox').observe('click', function(event) {if (event.element().id == 'lightbox') {closeLightbox();} });
}

/* automatische Initialisierung */
if (document.all) {
	if (!window.XMLHttpRequest) {
		document.write("<style type=\"text\/css\"> html {top: expression((typeof _E=='undefined') &&(document.body) &&(_E=document.body.currentStyle) &&(_dbs=document.body.style) &&((_E.backgroundImage!='none')||(_dbs.background=' '+_E.backgroundColor+' url(\"test.gif\") fixed')) &&((_E.backgroundAttachment=='fixed') ||((_P=_E.backgroundPositionX+' '+_E.backgroundPositionY) &&(this.style.background=' '+'transparent '+_E.backgroundImage+' '+_E.backgroundRepeat+' '+_E.backgroundAttachment+' '+_P)&&(_dbs.backgroundImage='none') &&(_dbs.backgroundColor='transparent') &&(setTimeout(function(){document.documentElement.style.setexpression(\"backgroundPosition\", \"document.body.currentStyle.backgroundPositionX+' '+document.body.currentStyle.backgroundPositionY\")},0)))) &&(setTimeout(function(){eval('document.documentElement.style.top=\"0px\"')},0)));}<\/style>");
	}
	Event.observe(window,'load', function () { initLightBox(); });		// IE
} else {
	document.observe('dom:loaded', function () { initLightBox(); });	// andere Browser
}

