
// --------------------------------------------------
// Allgemeine Shop-Funktionen
// --------------------------------------------------


function wopen(link,wi,he) {
	
	var width = wi ; 
	var height = he ;
	var l = (screen.availWidth-width)/2 ;
	var t = (screen.availHeight-height)/2 ;
    
    wincom = window.open(link ,"oswin","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width="+wi+",height="+he+",screenX="+l+",screenY="+t+",left="+l+",top="+t);
    
    if ( wincom ) {
    
    	wincom.focus() ;
    }
}

function wopen2(link,wi,he) {
	
	var width = wi ;
	var height = he ;
	var l = (screen.availWidth-width)/2 ;
	var t = (screen.availHeight-height)/2 ;
    
    wincom2 = window.open(link ,"oswin","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width="+wi+",height="+he+",screenX="+l+",screenY="+t+",left="+l+",top="+t);
    
    if ( wincom2 ) {
    
    	wincom2.focus() ;
    }
}

function tabbgcolor(tabid,col) {
	
	tabid.style.backgroundColor = col;
}

function fielddel(f) {

	if (f.value == f.defaultValue) {
	
		f.value = "" ;
	}
}


function fieldset(f) {

	if (f.value == "") {
		
		f.value = f.defaultValue ;
	}
}


function fieldemp(f) {

	if (f.sbeg.value == f.sbeg.defaultValue) {
		
		f.sbeg.value = "" ;
	}
}



// --------------------------------------------------
// DIV-Popupup-Funktionen
// --------------------------------------------------


var PopupDiv = {
	
	popupid: null ,

	show: function( divid , tiframe ,  url ) {
		
		var arrayPageSize = PopupDivGetPageSize();
		$('PopupDivBG').style.height = arrayPageSize[1] + 'px' ;
		Effect.Appear('PopupDivBG',{duration:0.3,to:0.6}) ;

		PopupDiv.popupid = divid ;		
		var popup = $(PopupDiv.popupid) ;
		
		popup.scrollTop = 0 ;
		PopupDivCenter(popup) ;
		Element.hide(PopupDiv.popupid) ;
		Effect.Appear(PopupDiv.popupid,{duration:0.1}) ;

		if ( url ) {
			if ( tiframe ) {
				$(tiframe).src = shopimgpath + 'trenner.gif' ;
				$(tiframe).src = url ;
			} else {
				new Ajax.Updater(PopupDiv.popupid,url,{encoding:'iso-8859-1'}) ;
			}
		}
		
		window.onresize = PopupDivResize ;
		window.onscroll = PopupDivResize ;
	} ,

	close: function() {
		
		Effect.Fade(PopupDiv.popupid,{duration:0.1}) ;
		Effect.Fade('PopupDivBG',{duration:0.1}) ;
	} 
}


function PopupDivCenter(popupid) {
	
	popupid.style.visibility = 'hidden' ;
	popupid.style.display    = 'block' ;
	
	var divh = PopupDivGetPageScroll() - popupid.getHeight() / 2 ;
	var divw = 0 - popupid.getWidth() / 2 ;
	
	popupid.style.display    = 'none';
	popupid.style.visibility = '';
	popupid.style.marginTop  = divh + 'px' ;
	popupid.style.marginLeft = divw + 'px' ;
}


function PopupDivResize() {
	
	var arrayPageSize = PopupDivGetPageSize();
	PopupDivResizeCenter($(PopupDiv.popupid));
	$('PopupDivBG').style.height = arrayPageSize[1] + 'px' ;
}


function PopupDivResizeCenter(popupid) {
	
	var divh = PopupDivGetPageScroll() - popupid.getHeight() / 2 ;
	var divw = 0 - popupid.getWidth() / 2 ;
	
	popupid.style.marginTop  = divh + 'px' ;
	popupid.style.marginLeft = divw + 'px'  ;
}


function PopupDivGetPageSize(){
	
	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;
	}

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


function PopupDivGetPageScroll(){

	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;
	}

	return yScroll ;
}



// --------------------------------------------------
// END
// --------------------------------------------------
