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

function updateGBContent(id) {
	$('gb_white_overlay').fade({duration: 0.5,from:$('gb_white_overlay').getOpacity(),to:0.0});
	
	$('gb_loading_ani').hide();
	
	$('gb_text_'+id).innerHTML = $('gb_temp').innerHTML;
	$('gb_temp').innerHTML = "";
}

function displayLoading() {	
	$('gb_loading_ani').show();
}

function displayImg(img,id,title) {
	
	var gbid = showGrayBox();
	displayLoading();	
	
	new Ajax.Request('ajax/displayImage.php?img='+img+'&gbid='+gbid+'&id='+id,
	{
		method: 'get',
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {
		   	$('gb_title_'+gbid).innerHTML = title;
			$('gb_temp').update(t.responseText);	
			smoothCenter(gbid);
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}


function changeImg(img,id,gbid) {
	displayLoading();
	new Ajax.Request('ajax/displayImage.php?img='+img+'&gbid='+gbid+'&id='+id,
	{
		method: 'get',
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {		
			$('gb_text_'+gbid).innerHTML = "";
		   	$('gb_temp').update(t.responseText);
			smoothCenter(gbid);
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}

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


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

function request(method,url,ziel,postform,loadingani,newserialize){
	if($(loadingani)) $(loadingani).show();
	else loading(); //$(ziel).update("<img src='images/loading_sitemap.gif' />");
	//alert(loadingani);
	if(method=='post' || method=='POST'){
		//alert(postform);
		if(newserialize) var pbody=$(postform).serialize(true);
		var pbody=$(postform).serialize();
	}else var pbody="";
	new Ajax.Request(url, {
		method: method,
		postBody: pbody,
		onSuccess: function(t) {
			$(ziel).update(t.responseText);
			if($(loadingani)) $(loadingani).hide();
			else unloading();
		},
		onFailure: function(t) {
			$(ziel).update('Error ' + t.status + ' -- ' + t.statusText);
			if($(loadingani)) $(loadingani).hide();
			else unloading();
		},
		evalScript: true,
		asynchronous: true
		}
	);
}

function doAjax(method,url,ziel,postform,loadingani,newserialize) {	
	request(method,url,ziel,postform,loadingani,newserialize);
}

