var mylbox;
function myLightBox(uri,opt)
{
	if (!opt)
	{
		opt = {
	    anything:   1.0
	  };
	  
	}
	
	opt['width'] = opt['width'] ? opt['width'] : 600;
  opt['height'] = opt['height'] ? opt['height'] : 400;
  opt['html'] = opt['html'] ? opt['html'] : false;
  opt['iframe'] = opt['iframe'] ? opt['iframe'] : false;
  
  if (opt['userData'])
  {
  	uri+="&"+opt['userData'];  	
  }
	
	var pSize = getPageSize();
	
	var lbox = document.getElementById('ligthbox2');	
	if (!lbox)
	{						
		//alert("create");
		var objBody = document.getElementsByTagName("body")[0];
    var objOverlay = document.createElement("div");
    objOverlay.setAttribute('id','overlay2');
    objOverlay.style.height = eval(pSize[1]) + "px";
    objOverlay.style.display = "none";
    objOverlay.onclick = function()
    {
    	myLightBoxClose();
    }    
    objBody.appendChild(objOverlay);
    
    var objLightbox = document.createElement("div");
    objLightbox.setAttribute('id','lightbox2');
    objLightbox.className = 'linecolor3';
    objLightbox.style.display = "none";
    objBody.appendChild(objLightbox);     
    
    lbox = objLightbox;
	}
	
	lbox.style.width = eval(opt['width']) + "px";
  lbox.style.height = eval(opt['height']) + "px";
  lbox.style.left = eval((pSize[0] - opt['width'])/2) + "px";
  lbox.style.top = eval((pSize[1] - opt['height'])/2) + "px";
	
	var arrayPageScroll = getPageScroll();  
  //lbox.style.top = (arrayPageScroll[1] + (arrayPageSize[3] / 10)) + "px";
  //var newTop = (pSize[1]-arrayPageScroll[1])/2 - opt['height']/2
  //var newTop = (pSize[1] - opt['height'])/2 + arrayPageScroll[1]/2
  var newTop = (pSize[3] - opt['height'])/2 + arrayPageScroll[1] - 14 - 14;
  
  lbox.style.top = eval(newTop) + "px";
  //alert(eval(newTop));
	//alert(arrayPageScroll);
	//alert(pSize);
	
	if (opt['iframe'])
	{		
		lbox.innerHTML = '<iframe src="'+uri+'" width="'+opt['width']+'" height="'+(opt['height']-28)+'" scrolling="auto" frameborder="0" border="0"></iframe>';
		lbox.innerHTML+= '<p>&nbsp;</p>'; 
		lbox.innerHTML+= '<p><a href="javascript:myLightBoxClose();"><strong>Fenster schlie&szlig;en</strong></a></p>'; 
	}
	else
	if (opt['html'])
	{		
		lbox.innerHTML = opt['html'];
		
	}
	else
	{		
		//loadAjax(uri,'lightbox');
	}
	
	try
	{
		new Effect.Parallel([
			new Effect.Appear('overlay2', {sync: true, from: 0.0, to: 0.9 }),
			new Effect.Appear('lightbox2', {sync: true, from:0.0, to: 1 })
			], { 
		  duration: 0.8,
		  afterFinish:function()
		  {		  	
		  	try
				{
					document.getElementById('customerPLZ').focus();
					document.getElementById('customerPLZ').select();
				}
				catch(err){}
		  }
		});
	}catch(e) 
	{
		
		new Effect.Appear('overlay2', {from: 0.0, to: 0.9 });
		new Effect.Appear('lightbox2', {from:0.0, to: 1 });			
	}
	
	
	
}

function myLightBoxClose()
{
	document.getElementById('lightbox2').innerHTML = '';
	new Effect.Parallel([
		new Effect.Fade('overlay2', {sync: true }),
		new Effect.Fade('lightbox2', {sync: true })
		], { 
	  duration: 0.5,
	  afterFinish:function()
	  {
	  	document.getElementById('overlay2').style.display = "none";	  	
	  	document.getElementById('lightbox2').style.display = "none";
	  	
	  	var objBody = document.getElementsByTagName("body")[0];
	  	objBody.removeChild(document.getElementById('lightbox2'));
	  	objBody.removeChild(document.getElementById('overlay2'));
	  	
	  }
	});	
} 

function getAbsolutePosition(element) 
{
    var r = { x: element.offsetLeft, y: element.offsetTop };
    if (element.offsetParent) {
    var tmp = getAbsolutePosition(element.offsetParent);
    r.x += tmp.x;
    r.y += tmp.y;
    }
    return r;
};

function getPageSize(){
        
        var xScroll, yScroll;
        
        if (window.innerHeight && window.scrollMaxY) {        
                xScroll = window.innerWidth + window.scrollMaxX;
                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;
        
//        console.log(self.innerWidth);
//        console.log(document.documentElement.clientWidth);

        if (self.innerHeight) {        // all except Explorer
                if(document.documentElement.clientWidth){
                        windowWidth = document.documentElement.clientWidth; 
                } else {
                        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;
        }

//        console.log("xScroll " + xScroll)
//        console.log("windowWidth " + windowWidth)

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

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

function getPageScroll(){

        var xScroll, yScroll;

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

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

function evalScript(scripts)
{ try
  { if(scripts != "")
    { var script = "";
      scripts = scripts.replace(/<script[^>]*>([\s\S]*?)<\/script>/gi, function(){
                                   if (scripts !== null) script += arguments[1] + "\n";
                                    return "";});
      if(script) (window.execScript) ? window.execScript(script) : window.setTimeout(script, 0);
    }
    return false;
  }
  catch(e)
  { alert(e)
  }
}

function Numsort (a, b) 
{
  return a - b;
}

function Assozsort (a, b) 
{
	return (a > b) - (a < b);
}


function isNumber(str) {
  for(var position=0; position<str.length; position++){
	var chr = str.charAt(position)
        if  ( (chr < "0") || (chr > "9") ) 
              return false;
  };      
  return true;
};


function checkPLZ(plz)
{
	if(isNaN(plz)) return false;
	if (plz.length < 5) return false;
	return true;
}

function autofocus()
{
	
}
//Event.observe(window, 'load', function() { loadAC();});
