//window.onload=setup
windowNameDefault="gosmikrozeitung"

cWindows={
	options:new Array(
		"",
		"toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1",
		"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0",
		"toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1",
		"toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1",
		"toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1",
		"toolbar=1,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1",
		"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0",
		"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1",
		"toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1",
		"toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1"
		),

	dimensions:new Array(
		"",
		"width=360,height=200",
		"width=360,height=325",
		"width=450,height=425",
		"width=480,height=390",
		"width=680,height=480",
		"width=810,height=490",
		"width=600,height=425"
		)
}



function setup(){
	setWindow()
	outLinks(document.getElementsByTagName("A"));
	outLinks(document.getElementsByTagName("AREA"));
	if(document.body.className.toLowerCase().indexOf("popup")>-1){self.focus()}
	setTableZoom();
}


function druckversion(o){
	return p(o.href,"gosdruckversion",560,650,cWindows["options"][9])
}

function mediaarchiv(o){
	return p(o.href,"gosmediaarchiv",560,580,cWindows["options"][5])
}

function empfehlen(o){
	return p(o.href,"gosdruckversion",460,560,cWindows["options"][5])
}

function db(o){
	// datenblatt staff
	return p(o.href,'datenblatt',380,560,'scrollbars=1')
}

function mp(o){
	//	marktplatz popup window
	return p(o.href,"gosmarktplatz",587,560,cWindows["options"][5])
}

function suche(o){
	//	popup search window
	document.location=o.href;
	return false;
	//return p(o.href,"gossuche",460,560,cWindows["options"][5])
}

function quicksearch(o){
	//	Suche vom Form aus Untermenu aus
	if((typeof o).toLowerCase()!="object"){o=document.getElementById(o)}
	val=o.elements["searchText"].value;
	if((val.length>=5)&(Number(val).toString()==val)){
		document.location="/artikel/"+val+"/";
		return false;
	}else{
		//gossuche=p(o.action,"gossuche",460,560,cWindows["options"][5])
		//o.target="gossuche"
		o.submit()
		return false
	}
}

function hilfe(o){
	//	popup help window
	return p(o.href,'hilfe',400,454,cWindows["options"][5])
}

function sitemap(o){
	//	popup sitemap window
	return p(o.href,'sitemap',1010,500,cWindows["options"][5])
}

function popPic(o){
	// popup for graphic elements (verlag)
	return p(o.href,'zeitungGrafik',730,560,cWindows["options"][8])
}

function ev(o){
	// popup for events show
	return p(o.href,'eventsShow',580,560,cWindows["options"][5])
}

function impressum(o){
	return p(o.href,'impressum',400,225,'toolbar=0,scrollbars=1,resizable=1')
}

function disclaimer(o){
	return p(o.href,'disclaimer',480,320,'toolbar=0,scrollbars=1,resizable=1')
}

function anmelden(o){
	return p(o.href,'anmelden',480,560,'toolbar=0,scrollbars=1,resizable=0')
}

function stickies(a){
	if(a){document.getElementById("stickies").style.display="block"}
	else{document.getElementById("stickies").style.display="none"}
//	setcookie("stickycookie",a,"/",365)
}

function setStickies(){
//	stickies(getcookie("stickycookie"))
}

function clearDates(){
	oForm.elements["datefrom"].value=""
}

function showSearchFields(a){
	document.getElementById("div_"+a.id).className=(document.getElementById("div_"+a.id).className=="pas"?"akt":"pas")
	a.className=(a.className=="pas"?a.className.replace("pas","akt"):a.className.replace("akt","pas"))
}

getFormFieldValue=function(o){
	if((!o.type)||(o.type=="checkbox")){return isChecked(o)?o.value:""}	//	checkbox or radio button
	else if(o.type.indexOf("select")==0){return (o.options[o.selectedIndex].value)}	//	pulldown
	else{return (o.value)}	//	hidden and text fields
}


collateFilledFields=function(oForm,mode){
	// cr 20060126 mh
	if(!document.getElementById){return true}
	if(oForm){
		if(!mode){mode="GET";}
		if((typeof oForm).toLowerCase()!="object"){oForm=document.getElementById(oForm);}
		switch(mode){
			case "GET":
				oForm.action=self.location.href.replace(self.location.search,"").replace(self.location.hash,"");
				cFields=new Array();
				for(var i=0;i<oForm.elements.length;i++){
					var val_tmp=getFormFieldValue(oForm.elements[i]);
					if(val_tmp!=""){cFields[cFields.length]=oForm.elements[i].name+"="+escape(val_tmp);}
				}
				if(cFields.length>0){
					oForm.action+="?"+cFields.join("&");
					self.location.href=oForm.action;
				}else{
					deAlert("F(ue)llen Sie bitte mindestens ein Feld aus.")
				}
				break;
			case "POST":
				//	incomplete
		}
	}
	return false
}

setRSSLinks=function(){
	cLinks=document.getElementsByTagName?document.getElementsByTagName("A"):document.links;
	for (var i=0; i<=(cLinks.length-1);i++){
		var a=cLinks[i];
		if((a.className.indexOf("rsslink")>-1)&&(!bw.safari)){
			a.onclick=function(){
				if(deConfirm("RSS-Feeds (\"Newsfeeds\") sind nicht f(ue)r standard "+(bw.ie?"\nWebbrowser wie Internet Explorer ":"Webbrowser ")+"geeignet.\n\nM(oe)chten Sie mehr (ue)ber RSS wissen?")){
					win_rssinfo=p("http://de.wikipedia.org/wiki/RSS","rssInformation",0,0,cWindows["options"][9]);
					if(popupBlocked(win_rssinfo)){
						deAlert("Ein ben(oe)tigte Popup-Fenster konnte dank Ihren\rBrowsereinstellungen nicht ge(oe)ffnet werden.\r\rBitte passen sie die Browsereinstellungen an,\rund klicken Sie wieder auf den orangen Knopf.");
					}
				}
				return false;
			}
		}
	}
}

Marktplatz={
	Sort:function(objID,formid){
		if(document.getElementById(objID).options[document.getElementById(objID).selectedIndex].value!=""){
			self.location.href=document.getElementById(formid).action+document.getElementById(objID).options[document.getElementById(objID).selectedIndex].value;
		}
	}
}



function ajaxPreview(mode,obj,recID){
	
	var myA=$('line_'+recID).down('a', 0);
	
	
	if($('preview_'+recID).style.height != "0px"){
		slideup('preview_'+recID);
		lastRecID='';
		currentRecID='';
		myA.removeClassName('cur');
		return false;
	}
	
	url=obj.href;
	currentRecID=recID;
	if(lastRecID){
		$('line_'+lastRecID).down('a', 0).removeClassName('cur');
	}

	myA.addClassName('cur');

	new Ajax.Request(url, {
		encoding:'UTF-8',
		method: 'post',
		postBody:'previewMode=ajax',
		onComplete:function(transport){
			//$('preview').update(eval((transport.responseText)));
			if(lastRecID){
				//toggleSlide('preview_'+lastRecID);					

				//$('preview_'+lastRecID).update('');
				//$('line_'+lastRecID).toggle();
				//toggleSlide('line_'+lastRecID);
				//slidedown('line_'+lastRecID);					
			}

			//$('line_'+currentRecID).toggle();	
			
			$('preview_'+currentRecID).update(transport.responseText);
			//toggleSlide('line_'+currentRecID);
			
			if(lastRecID){

				//crossfade('preview_'+currentRecID,'preview_'+lastRecID);
				slidedown('preview_'+currentRecID);
				slideup('preview_'+lastRecID);

			}else{
				$('line_'+currentRecID).scrollTo();
				slidedown('preview_'+currentRecID);

			}
			
			lastRecID=currentRecID;
		}

	});
};



function ajaxSinglePreview(mode,obj,myID){

	if($('preview_'+myID).style.height != "0px"){
		slideup('preview_'+myID);
		$(obj).removeClassName('cur');
		return false;
	}

	$(obj).addClassName('cur');

	url=obj.href;
	
	new Ajax.Request(url, {
		encoding:'UTF-8',
		method: 'post',
		postBody:'previewMode=ajax&mode=info&targetID='+myID,
		onComplete:function(transport){
			theReqBody=transport.request.body;
			aBody=theReqBody.toQueryParams();
			targetID=aBody['targetID'];
			$('preview_'+targetID).update(transport.responseText);
			slidedown('preview_'+targetID);
		}

	});
	return false;
};

/* fuer Blaettern2 - Liste  */
function createPagelist(list){
	var page='';
	var aList=list.split(',');
	var text='';
	var m=aList.length;
	for(var n=0;n<m;n++){
		page=aList[n];
		if(page!=""){
			text+=(page.charAt(0)=='<') ? page :'<a href=\"?page='+page+'\" onclick=\"return(blaetternSearch('+page+'));\">'+page+'</a>\n';
		}
	}
	document.write(text);
}


function searchHighlight(searchText){


}

/* ----   events ----*/
function events_dosearch(){
	//	check and submit events search form
	myForm=document.getElementById('eventsearch');
	var tDate=dateValiddate(myForm.elements["datefrom"].value)
	if(tDate){
		var aRange=new Array("tag","woche","wochenende","monat")
		myForm.elements["datefrom"].value=tDate
		goto_path=myForm.action
		var aDate=tDate.split(".")
		goto_path+=aDate[2]+"-"+aDate[1]+"-"+aDate[0]+"-"
		goto_path+=aRange[myForm.elements["datemode"].selectedIndex]
		//+ ((myForm.elements["dateto"].value!="")?"-"+myForm.elements["dateto"].value:"")
		goto_path+="/"
		goto_path+=((selValue(myForm.elements["rubrik"]).replace("*","").replace("alle","")!="")?selValue(myForm.elements["rubrik"])+"/":"")
		goto_path+=((myForm.elements["stichwort"].value!="")?"?stichwort="+escape(myForm.elements["stichwort"].value):"")
		self.location=goto_path
	}
	return false
}


/* --- date ----*/

//	Is this a valid date entry in the format dd.mm.yyyy?
function dateValiddate(a){
	if(a!=""&&a!="00.00.00"&a!="0.0.0"){
		var okFlag=true
		aDate=a.split('.')
		if(aDate.length<3||a.lastIndexOf('.')>=a.length-2){okFlag=false}

		var d=integer(aDate[0])
		var m=integer(aDate[1])
		var y=integer(aDate[2])
		if(d+""=="NaN"||y+""=="NaN"||y+""=="NaN"){okFlag=false}
		if(m>12){okFlag=false}
		if(d>31){okFlag=false}
		if(y<70){y=y+2000}
		else if(y>=70&&y<1900){y=y+1900}
		if(d<10){d="0"+d}
		if(m<10){m="0"+m}
		var theDate=d+"."+m+"."+y

		if(d>27 && m==2){
			var febdays=((((y % 4==0) && (y % 100!= 0))||(y % 400==0)))?29:28	//	leap year
			if(m==2 && d>febdays){okFlag=false}
		}

		if(okFlag){
			return theDate;
		}else{
			alert('Das eingegebene Datum ist ungueltig!')
			return false;
		}
	}else{
		alert('Kein Datum vorhanden');
		return false;
	}
}




//	Open popup window containing calendar.
function dateOpenCalendar(a){
	actField=a
	actDate=a.value;
	if(((actDate!="")&&(actDate!="00.00.00"))){if(!dateValiddate(actDate)){return false}}
	wWidth=180;
	wHeight=220;
	var windowPosition=centre_window(wWidth,wHeight)
	options="menubar=0,location=0,toolbar=0,directories=0,status=0,resizable=0,scrollbars=0,width="+wWidth+",height="+wHeight+",left="+windowPosition[0]+",top="+windowPosition[1];
	link="/common/calendar.gos";
	locCalendarWin=window.open(link,'calendarWin',options);
	if(parent){
		if(parent.extWin){
			parent.extWin[parent.counter]=locCalendarWin;
			parent.counter++;
		}
	}
	return false
}


function setTableZoom(){
	for(var n=1;n<5;n++){
		var myObj=$('sourcetable'+n);
		if(myObj){

			if(myObj.hasClassName('zoomable')){
				
				if(!document.aTableZoom){
					document.aTableZoom=new Object;
				}

				imgObj= document.createElement('img');
				$(imgObj).setAttribute('id','sourcetableicon'+n);
				imgObj.src='/i/icn/tablezoom_in.png';
				myObj.appendChild(imgObj);

				imgObj.observe('click', evClickTableZoom);
				
				var myIconObj=imgObj	//$('sourcetableicon'+n);
				var myTable=myObj.adjacent('table')[0];
				var myObj=myTable.parentNode;
				myObj.setStyle({ width:'400px',zIndex:'1000'});

				var w=myTable.offsetWidth;
				var myfontsize=400/w*10;
				if(myfontsize>9){
					myfontsize=9;
				}

				document.aTableZoom['sourcetable'+n]=myfontsize;
				//$(myObj).fTableZoom({origFontSize:myfontsize});				
				var nodes2 = myTable.select('td');
				nodes2.each(function(s) { 
					s.setStyle({ fontSize: myfontsize+'px' });
				}); 
	
				myIconObj.style.position = 'absolute';
				
				var offsets = myTable.cumulativeOffset();
				myIconObj.style.top    = myTable.offsetTop+ 'px';	//offsets[1]
				myIconObj.style.left   = (myTable.offsetWidth-30) + 'px';
				
			}
		}else{
			break;
		}
	
	}

}

function evClickTableZoom(event){
	tablezoom($(event.element()).id.substr(15));	// nur die Nr uebergeben

}

function tablezoom(source){

	//alert($(sourceid).innerHTML);
	//$(sourceid).absolutize;
	var myObj=$('sourcetable'+source);
	var nodes2 = myObj.select('td');
	var myIconObj=$('sourcetableicon'+source);
	var myTable=myObj.adjacent('table')[0];
	

	if(myObj.getStyle('width')=="700px"){
		myObj.setStyle({ width: '400px' });
		imgObj.src='/i/icn/tablezoom_in.png';
		var myfontsize=document.aTableZoom['sourcetable'+source];
		nodes2.each(function(s) { 
			s.setStyle({ fontSize: myfontsize+'px' });
		}); 
	}else{
		myObj.setStyle({ width:'700px',zIndex:'1000'});
		imgObj.src='/i/icn/tablezoom_out.png';		
		nodes2.each(function(s) { 
			s.setStyle({ fontSize: '10px' });
		}); 

	}

	    myIconObj.style.left   = (myTable.offsetWidth-30) + 'px';

	//nodes2.setStyle({ "font-size": "12px" });
	//$A(myObj.map(Element.extend).invoke('hide'); 

	//myObj.setStyle("font-size: 12px;");
	
	return(false);
//	return p("/common/tablezoom.gos?st="+sourceid+"&popupZoom="+popupzoom,"tablezoom",780,560,cWindows["options"][9])
}



/* ---------- motionpack Slide -------- */


var timerlen = 5;
var slideAniLen = 250;

var timerID = new Array();
var startTime = new Array();
var obj = new Array();
var endHeight = new Array();
var moving = new Array();
var dir = new Array();

function slidedown(objname){
	if(moving[objname])
		return;
	
	if($(objname).style.height != "0px")
		return; // cannot slide down something that is already visible
	
	$(objname).setStyle({'height' : $(objname).scrollHeight + 'px'});
	moving[objname] = true;
	dir[objname] = "down";
	startslide(objname);
}

function slideup(objname){
	if(moving[objname])
		return;
	
	if($(objname).style.height == "0px")
		return; // cannot slide up something that is already hidden
	
	moving[objname] = true;
	dir[objname] = "up";
	startslide(objname);
}

function startslide(objname){
	obj[objname] = $(objname);
	
	endHeight[objname] = parseInt(obj[objname].style.height);
	startTime[objname] = (new Date()).getTime();
	if(dir[objname] == "down"){
		obj[objname].style.height = "1px";
	}
	
	timerID[objname] = setInterval('slidetick(\'' + objname +'\');',timerlen);
}

function slidetick(objname){
	var elapsed = (new Date()).getTime() - startTime[objname];
	
	if (elapsed > slideAniLen)
		endSlide(objname)
		else {
			var d =Math.round(elapsed / slideAniLen * endHeight[objname]);
			if(dir[objname] == "up")
				d = endHeight[objname] - d;
			
			obj[objname].style.height = d + "px";
		}
	
	return;
}

function endSlide(objname){
	clearInterval(timerID[objname]);
	
	if(dir[objname] == "up")
		obj[objname].style.height = "0px";
	else
		obj[objname].style.height = endHeight[objname]+"px";	//damit auch wirklich endgroesse erreicht
	
	delete(moving[objname]);
	delete(timerID[objname]);
	delete(startTime[objname]);
	delete(endHeight[objname]);
	delete(obj[objname]);
	delete(dir[objname]);
	
	return;
}

function toggleSlide(objname){
	if($(objname).style.height == "0px"){
		// div is hidden, so let's slide down
		var questions = $('questions').getElementsByTagName('div');
		var questions= $A(questions);
		questions.each(function(question){
					   if(question.style.height != "0px") slideup(question);
					   });
		slidedown(objname);
	}else{
		// div is not hidden, so slide up
		slideup(objname);
	}
}
