
function executeFuntionsForOnLoad(link) {
	
	setContainerStatus(link);
	if(isSlideShow == '1') {
		initSlideShow();
	}
}

/* Show/Hide Extended SearchFields */

function setContainerStatus(link) {
	
	searchContainerVisible = readCookie('visible');
	currentSearch = readCookie('currentSearch');
	
	if(currentSearch == false){
		currentSearch = 'rezept';
		writeSessionCookie ('currentSearch', currentSearch);
	}
	
	suchbereich = document.getElementById("suchbereich");
	
	if(suchbereich != null){
	
		for(index=0; index<suchbereich.options.length; index++){
			if(suchbereich.options[index].value == currentSearch){
				suchbereich.selectedIndex = index;
			}
		}
		
		setFormAction(currentSearch, link);
		
		if(currentSearch == 'rezept_personal'){
			detailSearchObject = "detailsearch_rezept";
		}
		else {
			detailSearchObject = "detailsearch_" + currentSearch;
		}
		
		/*if (searchContainerVisible == 'true') {			
			document.getElementById(detailSearchObject).style.display = 'inline';				
		} else {			*/
			document.getElementById(detailSearchObject).style.display = 'none';
/*		} */
		writeSessionCookie ('visible', 'false');
	}
}

function changeContainerStatus() {
	
	searchContainerVisible = readCookie('visible');
	currentSearch = readCookie('currentSearch');
		
	if(currentSearch == 'rezept_personal'){
		detailSearchObject = "detailsearch_rezept";
	}
	else {
		detailSearchObject = "detailsearch_" + currentSearch;
	}
	
	if (searchContainerVisible == 'true') {			
		searchContainerVisible = 'false';
		document.getElementById(detailSearchObject).style.display = 'none';
					
	} else {			
		searchContainerVisible = 'true';
		document.getElementById(detailSearchObject).style.display = 'inline';
	}
	writeSessionCookie ('visible', searchContainerVisible);
}

function changeFormAction(link) {
	
	var selIndex = 0;
	suchbereich = document.getElementById("suchbereich");
	selIndex = suchbereich.selectedIndex;
	value = suchbereich.options[selIndex].value.toLowerCase();
	
	setFormAction(value, link);
	
	currentSearch = readCookie('currentSearch');
	searchContainerVisible = readCookie('visible');
	
	if(currentSearch == 'rezept_personal'){
		detailSearchObject = "detailsearch_rezept";
	}
	else {
		detailSearchObject = "detailsearch_" + currentSearch;
	}
	
	if(value == 'rezept_personal'){
		newDetailSearchObject = "detailsearch_rezept";
	}
	else {
		newDetailSearchObject = "detailsearch_" + value;
	}
	
	if (searchContainerVisible == 'true') {
					
		document.getElementById(detailSearchObject).style.display = 'none';
		document.getElementById(newDetailSearchObject).style.display = 'inline';
	}
	
	writeSessionCookie ('currentSearch', value);
}

function changeFormActionInitial(value, link) {
	
	var selIndex = 0;
	suchbereich = document.getElementById("suchbereich");
	selIndex = suchbereich.selectedIndex;
	/*value = suchbereich.options[selIndex].value.toLowerCase();*/
	
	setFormAction(value, link);
	
	currentSearch = readCookie('currentSearch');
	searchContainerVisible = readCookie('visible');
	
	if(currentSearch == 'rezept_personal'){
		detailSearchObject = "detailsearch_rezept";
	}
	else {
		detailSearchObject = "detailsearch_" + currentSearch;
	}
	
	if(value == 'rezept_personal'){
		newDetailSearchObject = "detailsearch_rezept";
	}
	else {
		newDetailSearchObject = "detailsearch_" + value;
	}
	
	if (searchContainerVisible == 'true') {
					
		document.getElementById(detailSearchObject).style.display = 'none';
		document.getElementById(newDetailSearchObject).style.display = 'inline';
	}
	
	writeSessionCookie ('currentSearch', value);
}

function setFormAction(value, link){
	
	form = document.getElementById('searchboxform')

	if(value == 'rezept'){
		form.action = link + "rezepte/rezeptsuche/index.html";
		form.method = "get";
	}
	if(value == 'rezept_personal'){
		form.action = link + "rezepte/persoenlich/index.html";
		form.method = "get";
	}
	else if(value == 'lokal'){
		form.action = link + "lokale/lokalsuche/index.html";
		form.method = "get";
	}
	else if(value == 'winzer'){
		form.action = link + "winzer/winzersuche/index.html";
		form.method = "get";
	}
	else if(value == 'caterer'){
		form.action = link + "caterer/caterersuche/index.html";
		form.method = "get";
	}
	else if(value == 'kochschule'){
		form.action = link + "kochschulen/kochschulensuche/index.html";
		form.method = "get";
	}
	else if(value == 'mietkoch'){
		form.action = link + "mietkoch/mietkochsuche/index.html";
		form.method = "get";
	}
	else if(value == 'vinothek'){
		form.action = link + "vinothek/vinotheksuche/index.html";
		form.method = "get";
	}
	else if(value == 'seite'){
		form.action = link + "search/index.jsp";
		form.method = "get";
	}
}


function getCookie(name, defval) {
        var prefix = name + "=";
        var start = document.cookie.indexOf(prefix);
        if (start==-1) return defval;
        var end = document.cookie.indexOf(";", start+prefix.length);
        if (end==-1) end=document.cookie.length;
        var value=document.cookie.substring(start+prefix.length, end);
        return decodeURI(value);  // unescape(value);
}

/* write and read cookies */
function readCookie(cookieName) {
	var exp = new RegExp (escape(cookieName) + "=([^;]+)");
	exp.exec (document.cookie + ";");
	return unescape(RegExp.$1);
}

function writeSessionCookie (cookieName, cookieValue) {
    document.cookie = escape(cookieName) + "=" + escape(cookieValue) + "; path=/";
}

/* script für die zutatenliste */
zutatenliste = new Array();
var textAreaId = "zutatenliste";
var lastPos = 0;
var zutatEdit = false;
var regExp = /[;*].+/;

function writeValues(fieldValueArr) {
		
	html = "";
	html = "<strong>Zutatenliste : </strong>";
	
	if (fieldValueArr.length) {
		for (var i=0; i < fieldValueArr.length; i++) {
				fieldStr = fieldValueArr[i];
				var fieldStrArray = fieldStr.split(";");
				html += '<div><span>' + fieldStrArray[0] + ': ' + fieldStrArray[2] + ' ' + fieldStrArray[3] + ' ' + fieldStrArray[1] + ' (' + fieldStrArray[4] + ' ' + fieldStrArray[5] + ')</span>';
				html += '<a href="#" onClick="deleteValue(' + i + ');">';
				html += '<span class="delbutton">L&ouml;schen</span></a> | ';
				html += '<a href="#" onClick="editValue(' + i + ');">';
				html += '<span class="editbutton">Bearbeiten</span></a>';					
				html += '</div>';
		}
	}
		else
	{
		html += "<div style='color:red'></div>";
	}
	document.getElementById('zutaten').innerHTML = html;
}

function editValue(editId) {
	var zlisterow = zutatenliste[editId].split(";");
	document.getElementById("pos").value = zlisterow[0];
	document.getElementById("bezeichnung").value = zlisterow[1];
	document.getElementById("menge").value = zlisterow[2];
	document.getElementById("einheit").value = zlisterow[3];
	einheitSel.choose(zlisterow[3], zlisterow[3]);
	document.getElementById("anmerkung").value = zlisterow[4];
	document.getElementById("titel").value = zlisterow[5];		
	document.getElementById("saveButton").value = "Nächste Zutat";
	zutatEdit = true;
}

function deleteValue(delValue) {
	newArray = new Array();
	var j = 0;
	for (var i=0; i < zutatenliste.length; i++) {
		if (i!=delValue) {
			newArray[j]=zutatenliste[i];
			j++;
		}
	}
	//setFieldValue(newArray, getRequestParam());
	zutatenliste = newArray;
	writeValues(zutatenliste);
	lastPos--;
	clearFormData();
}	

function saveValues() {
	var selectBoxStr = "";
	if (zutatenliste.length) {
		for (var i=0; i < zutatenliste.length; i++) {
			selectBoxStr += zutatenliste[i]+'\n';
		}			
	}
	opener.document.getElementById(textAreaId).value=selectBoxStr;
	writeValuesSave(zutatenliste, '1');
}

function writeValuesSave(fieldValueArr, toOpener) {
		
	html = "";
	
	if (fieldValueArr.length) {
		for (var i=0; i < fieldValueArr.length; i++) {
				fieldStr = fieldValueArr[i];
				var fieldStrArray = fieldStr.split(";");
				html += '<span>' + fieldStrArray[0] + ': ' + fieldStrArray[2] + ' ' + fieldStrArray[3] + ' ' + fieldStrArray[1] + ' (' + fieldStrArray[4] + ' ' + fieldStrArray[5] + ')</span><br/>';				
		}
	}
		else
	{
		html += "<span style='color:red'></span>";
	}
	
	if(toOpener == '1'){
		opener.document.getElementById('zutaten').innerHTML = html;
	}
	else{
		document.getElementById('zutaten').innerHTML = html;
	}
}

function getPos() {
	pos =  document.getElementById("pos").value.replace(regExp, "");
	return pos;
}

function getFormData() {
	var formDataStr = "";

	formDataStr = document.getElementById("pos").value.replace(regExp, "") + ";";		
	formDataStr += document.getElementById("bezeichnung").value.replace(regExp, "") + ";";
	formDataStr += document.getElementById("menge").value.replace(regExp, "") + ";";
	formDataStr += document.getElementById("einheit").value.replace(regExp, "") + ";";
	formDataStr += document.getElementById("anmerkung").value.replace(regExp, "") + ";";
	formDataStr += document.getElementById("titel").value.replace(regExp, "") + ";*";
	return formDataStr;
}

function clearFormData() {
	document.getElementById("pos").value = lastPos;
	document.getElementById("bezeichnung").value = "";
	document.getElementById("menge").value = "";
	document.getElementById("einheit").value = "";
	einheitSel.choose('','');
	document.getElementById("anmerkung").value = "";
	document.getElementById("titel").value = "";
}

function insertZutat() {
	if (zutatEdit) {
		zutatEdit = false;
		document.getElementById("saveButton").value = "Nächste Zutat";
		var zutatenStr = getFormData();
		pos = getPos()-1;
		zutatenliste[pos]=zutatenStr;
		
		writeValues(zutatenliste);
	} else {
		var quantity = zutatenliste.length;
		var zutatenStr = getFormData();
		zutatenliste[quantity]=zutatenStr;
		writeValues(zutatenliste);
		lastPos++;
	}
	clearFormData();
}

function readTextAreaData() {
	var textAreaStr = opener.document.getElementById(textAreaId).value;		
	textAreaLineArray = textAreaStr.split("*");
	if (textAreaLineArray.length>1) {
		for (var i=0; i < textAreaLineArray.length-1; i++) {
			dummy = textAreaLineArray[i].replace(/\n/, "");
			zutatenliste[i] = dummy + "*";
			lastPos = i;
		}
		lastPos++;
	}
	lastPos++;
	writeValues(zutatenliste);
	clearFormData();
}

function readInputData() {
	var textAreaStr = document.getElementById(textAreaId).value;		
	textAreaLineArray = textAreaStr.split("*");
	if (textAreaLineArray.length>1) {
		for (var i=0; i < textAreaLineArray.length-1; i++) {
			dummy = textAreaLineArray[i].replace(/\n/, "");
			zutatenliste[i] = dummy + "*";
			lastPos = i;
		}
		lastPos++;
	}
	lastPos++;
	writeValuesSave(zutatenliste, '0');
}
	
function checkSaved() {
	alert("Speichern nicht vergessen");
	return false;
}

/* script für bilder bei den DorisObject-Formularen */
function removeHauptbild() {
    imageNode = document.getElementById('hauptbild_img');

    imageNode.parentNode.removeChild(imageNode);
    document.getElementById('hauptbild_upload').style.display = 'inline';
    document.getElementById('hauptbild_upload').disabled = false;
    document.getElementById('hauptbild_hidden').disabled = true;
}

/* script für runde comboboxen */
/*
 *	ComboBox
 *	By Jared Nuzzolillo
 *
 *	Updated by Erik Arvidsson
 *	http://webfx.eae.net/contact.html#erik
 *	2002-06-13	Fixed Mozilla support and improved build performance
 *
 */

Global_run_event_hook = true;
Global_combo_array    = new Array();

Array.prototype.remove=function(dx)
{ 
    if(isNaN(dx)||dx>this.length){self.status='Array_remove:invalid request-'+dx;return false}
    for(var i=0,n=0;i<this.length;i++)
    {  
        if(this[i]!=this[dx])
        {
            this[n++]=this[i]
        }
    }
    this.length-=1
}

function ComboBox_make()
{
    var bt,nm;
    nm = this.name+"txt"; 
    
    this.txtview = document.createElement("INPUT");
    this.txtview.type = "text";
    this.txtview.name = nm;
    this.txtview.id = nm;
    
    if(this.size == "1"){
		this.txtview.className = "combo-input-size1";
	}
	else if(this.size == "2"){
		this.txtview.className = "combo-input-size2";
	}
	else if(this.size == "3"){
		this.txtview.className = "combo-input-size3";
	}
	else if(this.size == "4"){
		this.txtview.className = "combo-input-size4";
	}
	else if(this.size == "5"){
		this.txtview.className = "combo-input-size5";
	}
	
    this.view.appendChild(this.txtview);
        
    this.valcon = document.createElement("INPUT");
    this.valcon.type = "hidden";
    this.view.appendChild(this.valcon)
   
    var tmp = document.createElement("IMG");
    tmp.src = "___";
    tmp.style.width = "1px";
    tmp.style.height = "0";
    this.view.appendChild(tmp);
    
    var tmp = document.createElement("SPAN");
    tmp.className = "combo-button";
    
	this.view.appendChild(tmp);
   	tmp.onfocus = function () { this.blur(); };
	tmp.onclick = new Function ("", this.name + ".toggle()");
}

function ComboBox_choose(realval,txtval)
{
    this.value         = realval;
    var samstring = this.name+".view.childNodes[0].value='"+txtval+"'"
    window.setTimeout(samstring,1)
    this.valcon.value  = realval;
    
    this.hiddenField.value = this.value;
}

function ComboBox_mouseDown(e)
{
    var obj,len,el,i;
    el = e.target ? e.target : e.srcElement;
    while (el.nodeType != 1) el = el.parentNode;
    var elcl = el.className;
    if(elcl.indexOf("combo-")!=0)
    {
				
        len=Global_combo_array.length
        for(i=0;i<len;i++)
        {
        
            curobj = Global_combo_array[i]
            
            if(curobj.opslist)
            {
                curobj.opslist.style.display='none'
            }
        }
    }
}

function ComboBox_handleKey(e)
{
    var key,obj,eobj,el,strname;
    eobj = e;
    key  = eobj.keyCode;
    el = e.target ? e.target : e.srcElement;
    while (el.nodeType != 1) el = el.parentNode;
    elcl = el.className
    if(elcl.indexOf("combo-")==0)
    {
        if(elcl.split("-")[1]=="input")
        {
            strname = el.id.split("txt")[0]
            obj = window[strname];
			
            obj.expops.length=0
            obj.update();
            obj.build(obj.expops);
            if(obj.expops.length==1&&obj.expops[0].text=="(No matches)"){}//empty
            else{obj.opslist.style.display='block';}
            obj.value = el.value;
            obj.valcon.value = el.value;
        }
     }
}

function ComboBox_update()
{
    var opart,astr,alen,opln,i,boo;
    boo=false;
    opln = this.options.length
    astr = this.txtview.value.toLowerCase();
    alen = astr.length
    if(alen==0)
    {
        for(i=0;i<opln;i++)
        {
            this.expops[this.expops.length]=this.options[i];boo=true;
        }
    }
    else
    {
        for(i=0;i<opln;i++)
        {
            opart=this.options[i].text.toLowerCase().substring(0,alen)
            if(astr==opart)
            {
                this.expops[this.expops.length]=this.options[i];boo=true;
            }
        }
    }
    if(!boo){this.expops[0]=new ComboBoxItem("(No matches)","")}
}


function ComboBox_remove(index)
{
    this.options.remove(index)
}

function ComboBox_add()
{
    var i,arglen;
    arglen=arguments.length
    for(i=0;i<arglen;i++)
    {
        this.options[this.options.length]=arguments[i]
    }
}

function ComboBox_build(arr)
{
    var str,arrlen
    arrlen=arr.length;
    
    str = '<table class="combo-list-width" ';
    if(this.size == "1"){
		str = str + 'style="width: 54px" ';
	}
	else if(this.size == "2"){
		str = str + 'style="width: 64px" ';
	}
	else if(this.size == "3"){
		str = str + 'style="width: 97px" ';
	}
	else if(this.size == "4"){
		str = str + 'style="width: 220px" ';
	}
	else if(this.size == "5"){
		str = str + 'style="width: 304px" ';
	}
    
    str = str + 'cellpadding=0 cellspacing=0>'
    var strs = new Array(arrlen);
    for(var i=0;i<arrlen;i++)
    {
        strs[i] = '<tr>' +
			'<td class="combo-item" onClick="'+this.name+'.choose(\''+arr[i].value+'\',\''+arr[i].text+'\');'+this.name+'.opslist.style.display=\'none\';"' +
			'onMouseOver="this.className=\'combo-hilite\';" onMouseOut="this.className=\'combo-item\'" >&nbsp;'+arr[i].text+'&nbsp;</td>' +
			'</tr>';
    }
    str = str + strs.join("") + '</table>'
    
    if(this.opslist){this.view.removeChild(this.opslist);}
    
    this.opslist = document.createElement("DIV")
    this.opslist.innerHTML=str;
    this.opslist.style.display='none';
    this.opslist.className = "combo-list";
    this.opslist.onselectstart=returnFalse;
    this.view.appendChild(this.opslist);    
}

function ComboBox_toggle()
{
    if(this.opslist)
    {
        if(this.opslist.style.display=="block")
        {
            this.opslist.style.display="none"
        }
        else
        {
            this.update();
            this.build(this.options);
            this.view.style.zIndex = ++ComboBox.prototype.COMBOBOXZINDEX
            this.opslist.style.display="block"
        }
    }
    else
    {
        this.update();
        this.build(this.options);
        this.view.style.zIndex = ++ComboBox.prototype.COMBOBOXZINDEX
        this.opslist.style.display="block"
    }
}

function ComboBox()
{
    if(arguments.length==0)
    {
        self.status="ComboBox invalid - no name arg"
    }

    this.name     = arguments[0];
    this.size	  = arguments[1];
	this.par      = arguments[2]||document.body
	this.hiddenField = arguments[3]
    this.view     = document.createElement("DIV");
    
    if(this.size == "1"){
		this.view.className = "combo-div-size1";
	}
	else if(this.size == "2"){
		this.view.className = "combo-div-size2";
	}
	else if(this.size == "3"){
		this.view.className = "combo-div-size3";
	}
	else if(this.size == "4"){
		this.view.className = "combo-div-size4";
	}
	else if(this.size == "5"){
		this.view.className = "combo-div-size5";
	}
   
    this.options  = new Array();
    this.expops   = new Array();
    this.value    = ""

    this.build  = ComboBox_build
    this.make   = ComboBox_make;
    this.choose = ComboBox_choose;
    this.add    = ComboBox_add;
    this.toggle = ComboBox_toggle;
    this.update = ComboBox_update;
    this.remove = ComboBox_remove;

    this.make()
    this.txtview = this.view.childNodes[0]
    this.valcon  = this.view.childNodes[1]
    
    this.par.appendChild(this.view)

    Global_combo_array[Global_combo_array.length]=this;
    if(Global_run_event_hook){ComboBox_init()}
}

ComboBox.prototype.COMBOBOXZINDEX = 1000 //change this if you must

function ComboBox_init() 
{
	if (document.addEventListener) {
		document.addEventListener("keyup", ComboBox_handleKey, false );
		document.addEventListener("mousedown", ComboBox_mouseDown, false );
	}
	else if (document.attachEvent) {
		document.attachEvent("onkeyup", function () { ComboBox_handleKey(window.event); } );
		document.attachEvent("onmousedown", function () { ComboBox_mouseDown(window.event); } );
	}
	
    Global_run_event_hook = false;
}

function returnFalse(){return false}

function ComboBoxItem(text,value)
{
    this.text  = text;
    this.value = value;
}

var NS = (navigator.appName=="Netscape")?true:false; 

function fitPic() { 
	iWidth = (NS)?window.innerWidth:document.documentElement.clientWidth; 
	iHeight = (NS)?window.innerHeight:document.documentElement.clientHeight; 
	
    	iWidth = document.images[0].width - iWidth;
    	iHeight = document.images[0].height - iHeight;
	
	window.resizeBy(iWidth, iHeight); 
	self.focus(); 
}

function correctFooterMargin() {
	var divHeightCol1 = 0;
	var divHeightCol3 = 0;
	divHeightCol1 = document.getElementById('col1').offsetHeight;
	
	if(document.getElementById('col3') != null) {
		divHeightCol3 = document.getElementById('col3').offsetHeight;
	}

		
	if (divHeightCol1 > divHeightCol3)
		document.getElementById('footer').style.marginTop = (divHeightCol1 - divHeightCol3);
}

function fillAdTags(){
	writeAdTag('ad_Top_dummy', 'ad_Top');
}