var my_open = false;
function checkedDownload(form)
{
    new Ajax.Request('/download',
    {
        method: 'post',
        parameters: {data: $H($(form).serialize(true)).toJSON()}
    }
    );
}
function newwin(url, width, height, bgurl, top, left, scrollbars, resizable)
{
    if(width != undefined && width > 0 && height > 0)
    {
        var jetzt = new Date();
        var name = "win_" + jetzt.getTime();
        left = left != undefined ? left : 0;
        top = top != undefined ? top : 0;
        scrollbars = (scrollbars != undefined && scrollbars == 1) ? ",scrollbars=yes" : "";
        resizable = (resizable != undefined && resizable ==1) ? ",resizable=yes" : "";
        f = window.open(url, name, "width=" + width + ",height=" + height + ",left=" + left + ",top=" + top + scrollbars + resizable);
    }else{
        f = window.open(url);
    }
    if(bgurl != undefined && bgurl != "")
            location.href = bgurl;
    f.focus;
}
function OrderWebcontainer(e)
{
    new Ajax.Request('/admin/listsortupdate',
    {
	method : 'post',
	parameters : {data: Sortable.serialize(e)
    }
    }
    );
}
function OrderWebcontainerelement(e)
{
    new Ajax.Request('/admin/listelementesortupdate',
    {
	method : 'post',
	parameters : {data: Sortable.serialize(e)
    }	
    }
    );
}
function OrderWebcontainerelement_right()
{
    new Ajax.Request('/admin/listelementesortupdate_right',
    {
	method : 'post',
	parameters : {data: Sortable.serialize('list_elemente_right')
    }	
    }
    );
}
function webcontaineraufwebseite(div,webseiteid)
{
    new Ajax.Request('/admin/webcontaineraufwebseite',
    {
        method: 'post',
        parameters: {zahl:div, webseiteid: webseiteid},
        onSuccess: function(transport)
        {
            $('webcontaineraufwebseite_'+div).innerHTML = transport.responseText;
	}        
    }
    );
}


function changeobjektklimages(key,immobilieID)
{
    new Ajax.Request('/fachkunden/pachtboerse/objektklimage',
    {
        method: 'post',
        parameters: {key: key, immobilieID:immobilieID},
        onSuccess: function(transport)
        {
	    $('pachtboerse_image').replace(transport.responseText);
        }        
    }
    );
}

function objektmehrinfo(div,immobilieID, anaus)
{
    new Ajax.Request('/fachkunden/pachtboerse/mehrinfo',
    {
        method: 'post',
        parameters: {div: div, immobilieID: immobilieID, anaus: anaus},
        onSuccess: function(transport)
        {
	    $(div).replace(transport.responseText);
        }        
    }
    );
}



function hide_download()
{
    // $('innerwarenkorb').hide();
    $('innerwarenkorb').hide();
}

function changeImages(div,webcontainerid,art)
{
    if(my_open != undefined && my_open == true)
        return false;
	
    my_open = true;
    
    if($('produktdetailcontainer'))
    {
        $('produktdetailcontainer').remove();
    }
	
    var objBody = $$('body')[0];

    objBody.appendChild(Builder.node('div',{id:'overlay'}));
	
    // var webcontainerid = tmp[1];
    new Ajax.Request('/bilddatenbank/images/'+webcontainerid,
    {
        method: 'post',
        parameters: {webcontainerID: webcontainerid, art: art},        
        onSuccess: function(transport)
        {
	    var data = transport.responseText.evalJSON();
            $(div).innerHTML += data.html;	
	    var arrayPageScroll = document.viewport.getScrollOffsets();
	    var Top = arrayPageScroll[1] + (document.viewport.getHeight() / 10);
	    var Left = arrayPageScroll[0];
	    $(div).setStyle({ top: Top + 'px', left: Left + 'px' }).show();
	    $('produkt_details').observe('click', (function(event) { if (event.element().id == 'produkt_details') closedetails(div) }));
	    
	    // stretch overlay to fill page and fade in
	    var arrayPageSize = getPageSize();
	    $('overlay').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px', opacity: 0.6});
	    $('overlay').observe('click', (function() { closedetails(div) }));
	    $$('div.zoomarea').each(initZoom);
	    showfieldset(1);
        }
    }
    );
}

function bildergalerie(div,webcontainerid,position,max)
{

    if(my_open != undefined && my_open == true)
        return false;
    
    my_open = true;
 
    if($('changewebcontainer'))
    {
        $('changewebcontainer').remove();
    }
    var objBody = $$('body')[0];

    objBody.appendChild(Builder.node('div',{id:'overlay'}));	
    // var webcontainerid = tmp[1];
    new Ajax.Request('/bildergalerie',
    {
        method: 'post',
        parameters: {webcontainerID: webcontainerid, position: position, max: max},        
        onSuccess: function(transport)
        {
            $(div).innerHTML += transport.responseText;	
	    var arrayPageScroll = document.viewport.getScrollOffsets();
	    var Top = arrayPageScroll[1] + (document.viewport.getHeight() / 10);
	    var Left = arrayPageScroll[0];
	    $(div).setStyle({ top: Top + 'px', left: Left + 'px' }).show();
	    $('edit_container').observe('click', (function(event) { if (event.element().id == 'edit_container') closechange(div) }));	    
	    // stretch overlay to fill page and fade in
	    var arrayPageSize = getPageSize();
	    $('overlay').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px', opacity: 0.6});
	    $('overlay').observe('click', (function() { closechange(div) }));
        }
    }
    );
}

var produktDaten = {};
produktDaten.anzahl = -1;
produktDaten.produktID = 0;
function auswahlaendern(selectbox)
{
    if(selectbox.id == 'produktID')
	produktDaten.produktID = selectbox.value;
    if(selectbox.id == 'anzahl')
	produktDaten.anzahl = selectbox.value;
	
    if(produktDaten.produktID > 0 && produktDaten.anzahl > -1)
    {
	anzahlaendern(produktDaten.produktID,produktDaten.anzahl);
    }
}

function anzahlaendern(produktID,anzahl)
{
    $('artikelnummer_preis').addClassName('laden');
    new Ajax.Request('/shop/anzahlaendern',
    {
        method: 'post',
        parameters: {produktID: produktID, anzahl: anzahl},
        onSuccess: function(transport)
        {
	    $('artikelnummer_preis').replace(transport.responseText);
	    $('artikelnummer_preis').removeClassName('laden');
        }        
    }
    );
}


function produktanzeigen(containertypID)
{
    if(containertypID==14)    
	$('produktanzeigen').toggle();
    else
	$('produktanzeigen').hide();
}




function produktdetails(div,webcontainerid)
{
    try
    {
	if(my_open != undefined && my_open == true)
	    return false;
	
	my_open = true;
	
	if($('changewebcontainer'))
	{
	    $('changewebcontainer').remove();
	}
	    
	var objBody = $$('body')[0];
    
	objBody.appendChild(Builder.node('div',{id:'overlay'}));
	    
	// var webcontainerid = tmp[1];
	new Ajax.Request('/shop/details/'+webcontainerid,
	{
	    method: 'post',
	    parameters: {webcontainerID: webcontainerid},        
	    onSuccess: function(transport)
	    {
		var data = transport.responseText.evalJSON();
		$(div).innerHTML += data.html;	
		var arrayPageScroll = document.viewport.getScrollOffsets();
		var Top = arrayPageScroll[1] + (document.viewport.getHeight() / 10);
		var Left = arrayPageScroll[0];
		$(div).setStyle({ top: Top + 'px', left: Left + 'px' }).show();
		$('edit_container').observe('click', (function(event) { if (event.element().id == 'edit_container') closechange(div) }));	    
		// stretch overlay to fill page and fade in
		var arrayPageSize = getPageSize();
		$('overlay').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px', opacity: 0.6});
		$('overlay').observe('click', (function() { closechange(div) }));
	    }
	}
	);
    }
    catch(e){}
}
function produktneuinwarenkorb(produktID, anzahl, neu)
{
    try
    {
    
    new Ajax.Request('/shop/wiederinwarenkorb',
    {
	method: 'post',
	parameters: {produktID: produktID, anzahl: anzahl, neu: neu},   
        onSuccess: function(transport)
        {
	    $('warenkorb_link').replace(transport.responseText);
        }    
    }
    );
    
    }
    catch(e)
    {
	console.log(e);
    }	
}

function produktinwarenkorb(this_form)
{
    new Ajax.Request('/shop/warenkorb',
    {
	method: 'post',
	parameters: this_form.serialize(true),        
	onSuccess: function(transport)
	{
	    var data = transport.responseText.evalJSON();
	    if(data.status == 'ok')
	    {
		$('warenkorb_link').innerHTML = data.html;
		this_form.reset();
		$('erfolgreichwarenkorb_'+data.mediaID).show();
		$$('.fehler').each(function(e)
		{
		    e.hide();
		});		    
	    }
	    else
	    {
		this_form.replace(data.html);	
	    }
	    
	}
    }
    );
}

function produktauswarenkorbklein(produktID)
{
    new Ajax.Request('/shop/auswarenkorbklein',
    {
        method: 'post',
        parameters: {produktID: produktID, anzahl: 0},
        onSuccess: function(transport)
        {
	   // $('innerwarenkorb').replace(transport.responseText);
	    $('warenkorb_link').replace(transport.responseText);
        }        
    }
    );
}
function produktauswarenkorb(produktID)
{
    var answer = confirm('Artikel wirklich aus Ihrem Warenkorb entfernen?')    
    if (answer)
    {    
	new Ajax.Request('/shop/auswarenkorb',
	{
	    method: 'post',
	    parameters: {produktID: produktID, anzahl: 0},
	    onSuccess: function(transport)
	    {
		// $('bestelluebersicht').innerHTML = transport.responseText;
		$('bestelluebersicht').replace(transport.responseText);
		produktauswarenkorbklein(produktID);
	    }        
	}
	);
    }
}
function produkteditwarenkorb(produktID)
{
 
    if($('grosse_' + produktID))
	grosse = $('grosse_'+produktID).value;
    else
	grosse = 0;
	
    anzahl = $('anzahl_'+produktID+'').value;
    new Ajax.Request('/shop/editwarenkorb',
    {
        method: 'post',
        parameters: {produktID: produktID, anzahl: anzahl, grosse: grosse},
        onSuccess: function(transport)
        {
	    $('bestelluebersicht').replace(transport.responseText);
	    warenkorbrefresh()	    
        }        
    }
    );    
}

function warenkorbrefresh()
{
    new Ajax.Request('/shop/warenkorbrefresh',
    {
	method: 'post',
	onSuccess: function(transport)
        {
	    $('warenkorb_link').replace(transport.responseText);
        }    
    }
    );   
}

function abweichendelieferadresse(anaus)
{
    new Ajax.Request('/shop/lieferadresse',
    {
	method: 'post',
	parameters: {anaus: anaus},
	onSuccess: function(transport)
	{
	    $('lieferadresse').innerHTML = transport.responseText;
	}
    }
    );
}
function neuespasswort(anaus)
{
    new Ajax.Request('/shop/neuespasswort',
    {
	method: 'post',
	parameters: {anaus: anaus},
	onSuccess: function(transport)
	{
	    $('neu_passwort').innerHTML = transport.responseText;
	}
    }
    );
}

function lightbox_text(div,seite,seitetext)
{
    new Ajax.Request('/lightbox_text',
    {
        method: 'post',
        parameters: {seite: seite, seitetext: seitetext},
        onSuccess: function(transport)
        {
            $(div).innerHTML = transport.responseText;
	    // vertical slider control
	    var slider1 = new Control.Slider('handle1', 'track1', {
		    axis: 'vertical',
		    range: $R(0, ($('scrollable1').scrollHeight-$('scrollable1').offsetHeight)/10),
		    onSlide: function(v) { scrollVertical(v, $('scrollable1'), slider1);  },
		    onChange: function(v) { scrollVertical(v, $('scrollable1'), slider1); }
	    });
	    
	    // scroll the element vertically based on its width and the slider maximum value
	    function scrollVertical(value, element, slider) {
		    $(element).scrollTop = Math.round(value/slider.maximum*($(element).scrollHeight-$(element).offsetHeight));
	    }
	 
	   // disable vertical scrolling if text doesn't overflow the div
	    if ($('scrollable1').scrollHeight <= $('scrollable1').offsetHeight) {
		    slider1.setDisabled();
		    $('track1').hide();
	    }
	    
	    // mouse wheel code from http://adomas.org/javascript-mouse-wheel/
	    function handle(delta) {
		    slider1.setValueBy(-delta);
	    }
	    
	    /** Event handler for mouse wheel event. */
	    function wheel(event){
		    var delta = 0;
		    if (!event) /* For IE. */
			    event = window.event;
		    if (event.wheelDelta) { /* IE/Opera. */
			    delta = event.wheelDelta/120;
			    /** In Opera 9, delta differs in sign as compared to IE. */
			    if (window.opera)
				    delta = -delta;
		    } else if (event.detail) { /** Mozilla case. */
			    /** In Mozilla, sign of delta is different than in IE.
			    * Also, delta is multiple of 3.
			    */
			    delta = -event.detail/3;
		    }
	    
		    /** If delta is nonzero, handle it.
		    * Basically, delta is now positive if wheel was scrolled up,
		    * and negative, if wheel was scrolled down.
		    */
		    if (delta)
			    handle(delta);
	    
		    /** Prevent default actions caused by mouse wheel.
		    * That might be ugly, but we handle scrolls somehow
		    * anyway, so don't bother here..
		    */
		    if (event.preventDefault)
			    event.preventDefault();
		    
		    event.returnValue = false;
	    }
	    
	    // mozilla
	    Event.observe('scrollable1', 'DOMMouseScroll', wheel);
	    
	    // IE/Opera
	    Event.observe('scrollable1', 'mousewheel', wheel);
	}        
    }
    );
}



function changebezahlart(div,bezahlartID)
{
    new Ajax.Request('/shop/bezahlart',
    {
        method: 'post',
        parameters: {bezahlartID: bezahlartID},
        onSuccess: function(transport)
        {
            $(div).innerHTML = transport.responseText;
	}        
    }
    );
}
var newHTML;
function bestellungabsenden()
{
    new Ajax.Request('/shop/absenden',
    {  
	onSuccess: function(transport)
	{
	    var data = transport.responseText.evalJSON();
	    if(data.status == 'ok')
	    {
		newHTML = data.html;
		bestellungok();
		// login fenster oben rechts anzeigen
		loginfenster();
		// warenkorb refreshen
		warenkorbrefresh();
		
		if(data.redirect != undefined && data.redirect.url != undefined)
		{
		    location.href = data.redirect.url;
		}
	    }
	    else
	    {
		// $('absende_container').replace(data.html);
		$('bestelluebersicht').replace(data.html);
	    }
	}
    }
    );
}
function loginfenster()
{
    new Ajax.Request('/loginfenster',
    {
	method: 'post',
	onSuccess: function(transport)
	{
	    $('login_fenster').innerHTML = transport.responseText;     
	}
    }
    );
}

function bestellungok(data)
{
    $('bestelluebersicht').innerHTML = newHTML;    
}
function warte(element)
{
    $(element).innerHTML = '<div id="waiting_sign"><img src="/media_data/images/chrome/preloader_02.gif" width="100" height="100" title="Ein Moment bitte..." alt="Ein Moment bitte..." /><p>Ein Moment bitte, Ihr Bestellung wird verarbeitet.</p></div>';
}

function GetRandom( min, max ) {
        if( min > max ) {
                return( -1 );
        }
        if( min == max ) {
                return( min );
        }
        return( min + parseInt( Math.random() * ( max-min+1 ) ) );
} 


function getFlashMovie(movieName) {
   var isIE = navigator.appName.indexOf("Microsoft") != -1; 
   return (isIE) ? window[movieName] : document[movieName];
}  
function headerPlay() {
   getFlashMovie("flashcontent_1547").play(); 
} 
function headerStop() {
   getFlashMovie("flashcontent_1547").stop(); 
}



function newsletter(div,seite,newsletterid)
{
    //   headerStop();   
    if(my_open != undefined && my_open == true)
        return false;
    
    my_open = true;

    if($('changewebcontainer'))
    {
        $('changewebcontainer').remove();
    }
    var objBody = $$('body')[0];

    objBody.appendChild(Builder.node('div',{id:'overlay'}));	
    // var webcontainerid = tmp[1];
    new Ajax.Request('/newsletter_status',
    {
        method: 'post',
        parameters: {seite: seite, newsletterid: newsletterid},        
        onSuccess: function(transport)
        {
            $(div).innerHTML += transport.responseText;	
	    var arrayPageScroll = document.viewport.getScrollOffsets();
	    var Top = arrayPageScroll[1] + (document.viewport.getHeight() / 10);
	    var Left = arrayPageScroll[0];
	    $(div).setStyle({ top: Top + 'px', left: Left + 'px' }).show();
	    $('edit_container').observe('click', (function(event) { if (event.element().id == 'edit_container') closechange(div) }));	    
	    // stretch overlay to fill page and fade in
	    var arrayPageSize = getPageSize();
	    $('overlay').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px', opacity: 0.8});
	    $('overlay').observe('click', (function() { closechange(div) }));
	    
	    // vertical slider control
	    var slider1 = new Control.Slider('handle1', 'track1', {
		    axis: 'vertical',
		    range: $R(0, ($('scrollable1').scrollHeight-$('scrollable1').offsetHeight)/10),
		    onSlide: function(v) { scrollVertical(v, $('scrollable1'), slider1);  },
		    onChange: function(v) { scrollVertical(v, $('scrollable1'), slider1); }
	    });
	    
	    // scroll the element vertically based on its width and the slider maximum value
	    function scrollVertical(value, element, slider) {
		    $(element).scrollTop = Math.round(value/slider.maximum*($(element).scrollHeight-$(element).offsetHeight));
	    }
	 
	   // disable vertical scrolling if text doesn't overflow the div
	    if ($('scrollable1').scrollHeight <= $('scrollable1').offsetHeight) {
		    slider1.setDisabled();
		    $('track1').hide();
	    }
	    
	    // mouse wheel code from http://adomas.org/javascript-mouse-wheel/
	    function handle(delta) {
		    slider1.setValueBy(-delta);
	    }
	    
	    /** Event handler for mouse wheel event. */
	    function wheel(event){
		    var delta = 0;
		    if (!event) /* For IE. */
			    event = window.event;
		    if (event.wheelDelta) { /* IE/Opera. */
			    delta = event.wheelDelta/120;
			    /** In Opera 9, delta differs in sign as compared to IE. */
			    if (window.opera)
				    delta = -delta;
		    } else if (event.detail) { /** Mozilla case. */
			    /** In Mozilla, sign of delta is different than in IE.
			    * Also, delta is multiple of 3.
			    */
			    delta = -event.detail/3;
		    }
	    
		    /** If delta is nonzero, handle it.
		    * Basically, delta is now positive if wheel was scrolled up,
		    * and negative, if wheel was scrolled down.
		    */
		    if (delta)
			    handle(delta);
	    
		    /** Prevent default actions caused by mouse wheel.
		    * That might be ugly, but we handle scrolls somehow
		    * anyway, so don't bother here..
		    */
		    if (event.preventDefault)
			    event.preventDefault();
		    
		    event.returnValue = false;
	    }
	    
	    // mozilla
	    Event.observe('scrollable1', 'DOMMouseScroll', wheel);
	    
	    // IE/Opera
	    Event.observe('scrollable1', 'mousewheel', wheel);
	}
    }
    );
}

function newsletterbox(div,seite,newsletterid)
{
    
    if(my_open != undefined && my_open == true)
        return false;
    
    my_open = true;
    
    if($('changewebcontainer'))
    {
        $('changewebcontainer').remove();
    }
    var objBody = $$('body')[0];
    
    objBody.appendChild(Builder.node('div',{id:'overlay'}));	
    // var webcontainerid = tmp[1];
    new Ajax.Request('/lightbox',
    {
        method: 'post',
        parameters: {seite: seite, newsletterid:newsletterid},        
        onSuccess: function(transport)
        {
            $(div).innerHTML += transport.responseText;	
	    var arrayPageScroll = document.viewport.getScrollOffsets();
	    var Top = arrayPageScroll[1] + (document.viewport.getHeight() / 10);
	    var Left = arrayPageScroll[0];
	    $(div).setStyle({ top: Top + 'px', left: Left + 'px' }).show();
	    $('edit_container').observe('click', (function(event) { if (event.element().id == 'edit_container') closechange(div) }));	    
	    // stretch overlay to fill page and fade in
	    var arrayPageSize = getPageSize();
	    $('overlay').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px', opacity: 0.8});
	    $('overlay').observe('click', (function() { closechange(div) }));
	}
    }
    );
}


function bildergalerie_weiter(div,webcontainerid,position,max)
{
    new Ajax.Request('/bildergalerie',
    {
        method: 'post',
        parameters: {webcontainerID: webcontainerid, position: position, max: max},        
        onSuccess: function(transport)
        {
            $(div).replace(transport.responseText);	    
	    $('edit_container').observe('click', (function(event) { if (event.element().id == 'edit_container') closechange(div) }));	    
	    $('overlay').observe('click', (function() { closechange(div) }));
        }
    }
    );
}







function show_table(key)
{
    $('table_'+key).toggle();
}





function showkontakt()
{
    $('kontakt_anfrage').toggle();
    switch($('kontakt_anfrage').getStyle('display'))
    {
	case 'none':
	    $('kontakt_aufnehmen_minplus').removeClassName('kontakt_aufnehmen_plus');
	    $('kontakt_aufnehmen_minplus').addClassName('kontakt_aufnehmen_minus');
	    break;
	case 'block':
	    $('kontakt_aufnehmen_minplus').removeClassName('kontakt_aufnehmen_minus');
	    $('kontakt_aufnehmen_minplus').addClassName('kontakt_aufnehmen_plus');
	    break;
    }
}
function showtable(key)
{
    $('table_teil_'+key).toggle();
    switch($('table_teil_'+key).getStyle('display'))
    {
	case 'table':
	    $('table_minplus_'+key).removeClassName('table_plus');
	    $('table_minplus_'+key).addClassName('table_minus');
	    break;
	case 'none':
	    $('table_minplus_'+key).removeClassName('table_minus');
	    $('table_minplus_'+key).addClassName('table_plus');
	    break;
    }
}
function showabsatz(key)
{
    $('table_teil_'+key).toggle();
}

function neuerpreis(key)
{
    $(key).toggle();
}
function changeCloseImages(mediaID)
{
    $('largeimages_'+mediaID).hide();
}

function changedaten(div,webcontainerid,webcontainerelementeID)
{
    if(my_open != undefined && my_open == true)
        return false;
	
    my_open = true;
    
    if($('changewebcontainer'))
    {
        $('changewebcontainer').remove();
    }
	
    var objBody = $$('body')[0];

    objBody.appendChild(Builder.node('div',{id:'overlay'}));
	
    // var webcontainerid = tmp[1];
    new Ajax.Request('/admin/webcontainer/edit/'+webcontainerid,
    {
        method: 'post',
        parameters: {webcontainerID: webcontainerid, webcontainerelementeID:webcontainerelementeID},        
        onSuccess: function(transport)
        {
            $(div).innerHTML += transport.responseText;
            if($('schlagwort_id'))
                tlist2 = new FacebookList('schlagwort_id', 'schlagwort-auto',{fetchFile:'/admin/schlagwort/get', setFile:'/admin/schlagwort/set'});
			
	    var arrayPageScroll = document.viewport.getScrollOffsets();
	    var Top = arrayPageScroll[1] + (document.viewport.getHeight() / 10);
	    var Left = arrayPageScroll[0];
	    $(div).setStyle({ top: Top + 'px', left: Left + 'px' }).show();
	    $('edit_container').observe('click', (function(event) { if (event.element().id == 'edit_container') closechange(div) }));
	    
	    // stretch overlay to fill page and fade in
	    var arrayPageSize = getPageSize();
	    $('overlay').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px', opacity: 0.6});
	    $('overlay').observe('click', (function() { closechange(div) }));
	    createEditor();	    
	    
	    
	    // new nicEditor({iconsPath : '/media_data/images/nicEditorIcons.gif', buttonList : ['bold','italic','underline','strikeThrough','subscript','superscript','ol','ul','link','unlink','removeformat','xhtml']}).panelInstance('inhalt',{hasPanel : true});
	    // new nicEditor({buttonList : ['bold','italic','underline','left','center','right','ol','ul','fontSize','fontFamily','fontFormat','superscript','subscript','indent','outdent','link','unlink','striketrhough','forecolor','bgcolor','image','upload','xhtml']}).panelInstance('inhalt');
	    //adddatepicker("#" + div);
        }
    }
    );
}

function changeprodukt(div,webcontainerid,webcontainerelementeID)
{
    if(my_open != undefined && my_open == true)
        return false;
	
    my_open = true;
    
    if($('changewebcontainer'))
    {
        $('changewebcontainer').remove();
    }
	
    var objBody = $$('body')[0];

    objBody.appendChild(Builder.node('div',{id:'overlay'}));
	
    // var webcontainerid = tmp[1];
    new Ajax.Request('/admin/produkt/edit/'+webcontainerid,
    {
        method: 'post',
        parameters: {webcontainerID: webcontainerid, webcontainerelementeID:webcontainerelementeID},        
        onSuccess: function(transport)
        {
            $(div).innerHTML += transport.responseText;
            if($('schlagwort_id'))
                tlist2 = new FacebookList('schlagwort_id', 'schlagwort-auto',{fetchFile:'/admin/schlagwort/get', setFile:'/admin/schlagwort/set'});
			
	    var arrayPageScroll = document.viewport.getScrollOffsets();
	    var Top = arrayPageScroll[1] + (document.viewport.getHeight() / 10);
	    var Left = arrayPageScroll[0];
	    $(div).setStyle({ top: Top + 'px', left: Left + 'px' }).show();
	    $('edit_container').observe('click', (function(event) { if (event.element().id == 'edit_container') closechange(div) }));
	    
	    // stretch overlay to fill page and fade in
	    var arrayPageSize = getPageSize();
	    $('overlay').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px', opacity: 0.6});
	    $('overlay').observe('click', (function() { closechange(div) }));
	    createEditor();
	    // new nicEditor({iconsPath : '/media_data/images/nicEditorIcons.gif', buttonList : ['bold','italic','underline','strikeThrough','subscript','superscript','ol','ul','link','unlink','removeformat','xhtml']}).panelInstance('inhalt',{hasPanel : true});
	    // new nicEditor({buttonList : ['bold','italic','underline','left','center','right','ol','ul','fontSize','fontFamily','fontFormat','superscript','subscript','indent','outdent','link','unlink','striketrhough','forecolor','bgcolor','image','upload','xhtml']}).panelInstance('inhalt');
	    //adddatepicker("#" + div);
        }
    }
    );
}


function weiter_artikeleigenschaften(eigenschaftID,anaus)
{
    new Ajax.Request('/admin/zusatz_eigenschaften',
    {
	method: 'post',
	evalJS: 'force',
	parameters: {eigenschaftID: eigenschaftID, anaus: anaus},
	onSuccess: function(transport)
	{
	    $('abweichende_eigenschaften_'+eigenschaftID).innerHTML = transport.responseText;
	    //new Control.DatePicker($('grosse_kaufab_'+eigenschaftID), {icon: '/media/images/chrome/calendar.gif', locale: 'de_DE', padding: 3});
	    //new Control.DatePicker($('grosse_kaufbis_'+eigenschaftID), {icon: '/media/images/chrome/calendar.gif', locale: 'de_DE', padding: 3});
	    // adddatepicker('^#abweichende_eigenschaften_'+eigenschaftID);
	}        
    }
    );
}

function changeelement(div,webcontainerelementid,webcontainerid)
{
    if(my_open != undefined && my_open == true)
        return false;
	
    my_open = true;
    
    if($('changewebcontainer'))
    {
        $('changewebcontainer').remove();
    }
	
    var objBody = $$('body')[0];

    objBody.appendChild(Builder.node('div',{id:'overlay'}));
	
    // var webcontainerid = tmp[1];
    new Ajax.Request('/admin/webcontainerelement/edit/'+webcontainerelementid,
    {
        method: 'post',
        parameters: {webcontainerelementID: webcontainerelementid, webcontainerID: webcontainerid},        
        onSuccess: function(transport)
        {
            $(div).innerHTML += transport.responseText;	
	    var arrayPageScroll = document.viewport.getScrollOffsets();
	    var Top = arrayPageScroll[1] + (document.viewport.getHeight() / 10);
	    var Left = arrayPageScroll[0];
	    $(div).setStyle({ top: Top + 'px', left: Left + 'px' }).show();
	    $('edit_container').observe('click', (function(event) { if (event.element().id == 'edit_container') closechange(div) }));
	    
	    // stretch overlay to fill page and fade in
	    var arrayPageSize = getPageSize();
	    $('overlay').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px', opacity: 0.6});
	    $('overlay').observe('click', (function() { closechange(div) }));
	    
	    // new nicEditor({iconsPath : '/media_data/images/nicEditorIcons.gif', buttonList : ['bold','italic','underline','strikeThrough','subscript','superscript','ol','ul','link','unlink','removeformat','xhtml']}).panelInstance('inhalt',{hasPanel : true});
	    // new nicEditor({fullPanel : true}).panelInstance('inhalt');
	    createEditor();
	    //adddatepicker("#" + div);
        }
    }
    );
}

function zusatzelement(div,webcontainerid,webseiteID)
{
    if(my_open != undefined && my_open == true)
        return false;
	
    my_open = true;
    
    if($('changewebcontainer'))
    {
        $('changewebcontainer').remove();
    }
	
    var objBody = $$('body')[0];

    objBody.appendChild(Builder.node('div',{id:'overlay'}));
	
    // var webcontainerid = tmp[1];
    new Ajax.Request('/admin/webcontainerelement/zusatz/'+webcontainerid,
    {
        method: 'post',
        parameters: {webcontainerID: webcontainerid, webseiteID: webseiteID},        
        onSuccess: function(transport)
        {
            $(div).innerHTML += transport.responseText;	
	    var arrayPageScroll = document.viewport.getScrollOffsets();
	    var Top = arrayPageScroll[1] + (document.viewport.getHeight() / 10);
	    var Left = arrayPageScroll[0];
	    $(div).setStyle({ top: Top + 'px', left: Left + 'px' }).show();
	    $('edit_container').observe('click', (function(event) { if (event.element().id == 'edit_container') closechange(div) }));
	    
	    // stretch overlay to fill page and fade in
	    var arrayPageSize = getPageSize();
	    $('overlay').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px', opacity: 0.6});
	    $('overlay').observe('click', (function() { closechange(div) }));
	    // new nicEditor({iconsPath : '/media_data/images/nicEditorIcons.gif', buttonList : ['bold','italic','underline','strikeThrough','subscript','superscript','ol','ul','link','unlink','removeformat','xhtml']}).panelInstance('inhalt',{hasPanel : true});
	    // new nicEditor({fullPanel : true}).panelInstance('inhalt');	   	    
	    //adddatepicker("#" + div);
	    createEditor();
      }
    }
    );
}
function bild_left()
{
    
}

function bild_right()
{
    
}



function closechange(div)
{
    my_open = false; 
    //$(div).remove();
    showfieldset(0);
    if(typeof removeEditor == "function")
	removeEditor();
    //if(typeof headerPlay == "function")
    //    headerPlay();	
    if($('changewebcontainer')) $('changewebcontainer').remove();
    if($('overlay')) $('overlay').remove();
}

function showfieldset(anaus)
{
    if(anaus==1)
	$$('select').invoke('hide');
    else
	$$('select').invoke('show');
}






function closedetails(div)
{
    my_open = false; 
    //$(div).remove();
    if($('produktdetailcontainer'))
	$('produktdetailcontainer').remove();
    if($('bilddetailcontainer'))
	$('bilddetailcontainer').remove();
    $('overlay').remove();
    if($('fieldset_suchen')) $('fieldset_suchen').show();
    showfieldset(0);	
}


function deletedaten(div,spruch)
{
    var tmp = div.split("_");
    var tmp_tmp = tmp[1].split(".");
    var webseiteid = tmp_tmp[0];
    var webcontainerid = tmp_tmp[1];    
    var ypos = tmp_tmp[3];
    var answer = confirm(spruch)    
    if (answer)
    {
        new Ajax.Request('/admin/webcontainer/delete/'+webcontainerid,
        {
            method: 'post',
            parameters: {ypos: ypos, webseiteid: webseiteid, webcontainerID: webcontainerid},
            onSuccess: function(transport)
            {
                $(div).remove();         
            }
        }
        );
    }    
}

function papierkorb(div,spruch)
{
    var tmp = div.split("_");
    var tmp_tmp = tmp[1].split(".");
    var webcontainerid = tmp_tmp[1];
    var answer = confirm(spruch)    
    if (answer)
    {
        new Ajax.Request('/admin/webcontainer/papierkorb/'+webcontainerid,
        {
            method: 'post',
            parameters: {webcontainerID: webcontainerid},
            onSuccess: function(transport)
            {
                $(div).remove();         
            }
        }
        );
    }
}
function adddatepicker()
{
    var inElement = "";
    if(adddatepicker.arguments.length)
    {
	inElement = adddatepicker.arguments[0] + " ";
    }
    $$(inElement + 'input.datepicker').each(function(e){
	 new Control.DatePicker($(e), {icon: '/media/images/chrome/calendar.gif', locale: 'de_DE', padding: 3});
    });
}

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;
	
	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;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	return [pageWidth,pageHeight];
}

function zusatzabsatz(zahl,anz)
{
    zahl = zahl + 1;
    new Ajax.Request('/admin/zusatzabsatz',
    {
        method: 'post',
        parameters: {zahl: zahl, anz: anz},
        onSuccess: function(transport)
        {
	    $('absatz_'+zahl).replace(transport.responseText);
	    createEditor('absatz_'+zahl);
	    // new nicEditor({iconsPath : '/media_data/images/nicEditorIcons.gif', buttonList : ['bold','italic','underline','strikeThrough','subscript','superscript','ol','ul','link','unlink','removeformat','xhtml']}).panelInstance('absatz_'+zahl,{hasPanel : true});
	}        
    }
    );
}
function zusatzproduktzuprodukt(zahl,anz,neu)
{
    zahl = zahl + 1;
    new Ajax.Request('/admin/zusatzproduktzuprodukt',
    {
        method: 'post',
        parameters: {zahl: zahl, anz: anz, neu: neu},
        onSuccess: function(transport)
        {
	    $('produkt_zu_produkt_'+zahl).replace(transport.responseText);
	}        
    }
    );
}
function zusatzproduktzuproduktneu(zahl,neu)
{
    // zahl = zahl + 1;
    new Ajax.Request('/admin/zusatzproduktzuproduktneu',
    {
        method: 'post',
        parameters: {zahl: zahl, neu: neu},
        onSuccess: function(transport)
        {
	    $('produkt_zu_produkt_'+zahl).replace(transport.responseText);
	}        
    }
    );
}
function zusatzprodukt(zahl,anz)
{
    zahl = zahl + 1;
    new Ajax.Request('/admin/zusatzprodukt',
    {
        method: 'post',
        parameters: {zahl: zahl, anz: anz},
        onSuccess: function(transport)
        {
	    $('zusatz_produkt_'+zahl).replace(transport.responseText);
	}        
    }
    );
}


function zusatzgalerie(zahl,anz)
{
    zahl = zahl + 1;
    new Ajax.Request('/admin/zusatzgalerie',
    {
        method: 'post',
        parameters: {zahl: zahl, anz: anz},
        onSuccess: function(transport)
        {
	    $('absatz_'+zahl).replace(transport.responseText);
	    createEditor();
	    // new nicEditor({iconsPath : '/media_data/images/nicEditorIcons.gif', buttonList : ['bold','italic','underline','strikeThrough','subscript','superscript','ol','ul','link','unlink','removeformat','xhtml']}).panelInstance('absatz_'+zahl,{hasPanel : true});
	}        
    }
    );
}

function kundenlogout(refresh)
{
    new Ajax.Request('/kundendaten/kundenlogout',
    {
        method: 'post',
	parameters: {refresh: refresh},
        onSuccess: function(transport)
        {
	    location.href='/kundenlogout';
	    /*
	    $('kundenlogout_div').replace(transport.responseText);
	    if(refresh==1)
	    {
		kundendaten(refresh);
	    }
	    */
	}        
    }
    );
}
function kundenlogin(this_form)
{
    new Ajax.Request('/kundendaten/kundenlogin',
    {
	method: 'post',
	parameters: this_form.serialize(true),        
	onSuccess: function(transport)
	{
	    var data = transport.responseText.evalJSON();
	    if(data.status == 'ok')
	    {
		// $('kundenlogin_div').innerHTML = data.html;
		$('kundenlogin_div').replace(data.html);
		this_form.reset();
	    }
	}
    }
    );
}

function kundenlogin_dateneingabe(this_form)
{
    new Ajax.Request('/kundendaten/kundenlogin_dateneingabe',
    {
	method: 'post',
	parameters: this_form.serialize(true),        
	onSuccess: function(transport)
	{
	    var data = transport.responseText.evalJSON();
	    if(data.status == 'ok')
	    {
		//$('kundenlogin_div').innerHTML = data.html;
		$('kundenlogin_div').replace(data.html);
		this_form.reset();
		kundendaten(1);
	    }
	}
    }
    );
}

function gutschein_ueberpruefen(this_form)
{
    new Ajax.Request('/shop/gutschein',
    {
	method: 'post',
	parameters: this_form.serialize(true),        
	onSuccess: function(transport)
	{
	    $('bestelluebersicht').replace(transport.responseText);    
	}
    }
    );
}


var show_erklaerbox = false;
function erklaerbox(erklaer_lnk)
{
    if(show_erklaerbox != erklaer_lnk.href)
    {
	new Ajax.Request('/erklaerbox',
	{
	    method: 'post',
	    parameters: {erklaerurl: erklaer_lnk.href},
	    onSuccess: function(transport)
	    {
		$('erklaer_box').replace(transport.responseText);
		$('erklaer_box').appear({ duration: 1.0, from: 0, to: 1 });
		show_erklaerbox = erklaer_lnk.href;
	    }        
	}
	);
    }
    else
    {
	$('erklaer_box').appear({ duration: 1.0, to: 0 });
    }
}
function erklaerbox_schliessen()
{
    show_erklaerbox = false;
    $('erklaer_box').appear({ duration: 1.0, to: 0 }); 
}

function kundendaten(refresh)
{
    new Ajax.Request('/kundendaten/kundendaten',
    {
        method: 'post',
	parameters: {refresh: refresh},
        onSuccess: function(transport)
        {
	    $('bestelldaten').replace(transport.responseText);
	}        
    }
    );
}




function deleteelement(div,spruch)
{
    var tmp = div.split("_");
    var tmp_tmp = tmp[1].split(".");
    var webcontainerid = tmp_tmp[1];
    var webcontainerelementid = tmp_tmp[2];
    var answer = confirm(spruch)    
    if (answer)
    {
        new Ajax.Request('/admin/webcontainerelement/delete/'+webcontainerelementid,
        {
            method: 'post',
            parameters: {webcontainerelementid: webcontainerelementid, webcontainerID: webcontainerid},
            onSuccess: function(transport)
            {
                $(div).remove();         
            }
        }
        );
    }
}

// 'divcontainer_{$webcontainerID}.{$unit["webcontainerelementID"]}','$spruch'

function delete_absatz(zahl)
{
    $('zusatz_absatz_'+zahl).remove();
}
function seite_pruefen()
{
    var neue_unterkategorie = $F('neue_unterkategorie');
    var kategorie = $F('kategorie');
    new Ajax.Request('/admin/neue_seite_ueberpruefen',
    {
	method: 'post',
	parameters: {neue_unterkategorie: neue_unterkategorie, kategorie: kategorie},
	onSuccess: function(transport)
	{
	    $('span_unterkategorie_haken').innerHTML = transport.responseText;        
	}
    }
    );
}

function unterseitenlinks()
{
    var webseiteID = $F('kategorie');
    new Ajax.Request('/admin/unterseitenlinks',
    {
	method: 'post',
	parameters: {webseiteID: webseiteID},
	onSuccess: function(transport)
	{
	    $('unterseitenlink').innerHTML = transport.responseText;        
	}
    }
    );
}

var IE = {
	detect: function() {
		var ua = navigator.userAgent;
		var MSIEOffset = ua.indexOf("MSIE ");
		if (MSIEOffset == -1) {
			this.version = 0;
		} else {
			this.version = parseFloat(ua.substring(MSIEOffset + 5, ua.indexOf(";", MSIEOffset)));
		}
	},
	version: 0
}
IE.detect();

function neue_unterseiten()
{
    new Ajax.Request('/admin/neue_unterseiten',
    {
        method: 'post',
        onSuccess: function(transport)
        {
	    // $('span_unterkategorie').innerHTML = transport.responseText;
	    $('span_unterkategorie').replace(transport.responseText);		    
	}        
    }
    );
}

function changeartikelart(art)
{
    new Ajax.Updater($('artikelart_field'), '/admin/artikelart',
    {
	method: 'post',
	parameters: {artID: art},
	onSuccess: function(transport)
	{
	    // nix
	}        
    }
    );
}


var li_styles = new Array();
function hover_menue(obj, dir)
{
    var normal, clicked;
    var allElems = obj.parentNode.childNodes;
    normal = 'closed';
    clicked = 'hover';
    if(dir == 0) // Mouse out
    {
	var o=0;
	for(var i=0; i<allElems.length; i++)
	{
	    if(allElems[i].nodeType != 3)
	    {
		if(allElems[i] != $('clicked'))
		{
		    allElems[i].className = normal;
		    allElems[i].down('a').writeAttribute("style", '');
		}
		else
		{
		    allElems[i].className = clicked;
		    allElems[i].down('a').writeAttribute("style", li_styles[o]);
		}
		o++;
	    }
	}
    }
    else
    {
	if(obj.className == clicked)
	    return;

	obj.className = clicked;
	var o =0;
	for(var i=0; i<allElems.length; i++)
	{
	    if(allElems[i].nodeType != 3)
	    {
		allElems[i].down('a').writeAttribute("style", '');
		if(allElems[i] == obj)
		    obj.down('a').writeAttribute("style", li_styles[o]);
		o++;
	    }
	    if( allElems[i] != obj && allElems[i].className == clicked)
	    {
		allElems[i].className = normal;
	    }
	}
    }
}

i=0;
document.observe("dom:loaded", function()
{
    // new text2img();


    $$('ul.seiten_nav li').each(
	function(s)
	{
	    li_styles[i] = $(s).down('a').readAttribute('style');
	    if($(s) != $('clicked')) $(s).down('a').writeAttribute("style", ''); 
	    $(s).observe('mouseover', function(){hover_menue(s, 1)}); 
	    $(s).observe('mouseout', function(){hover_menue(s, 0)});
	    i++;
	}
    );
	
	$$('a').each(
	function(s)
	{
	    if(s.href.toUpperCase().indexOf('HTTP://') > -1 && s.href.toUpperCase().indexOf(window.location.hostname.toUpperCase()) == -1)
		{
			s.onclick = function(){newwin(s.href); return false;};
		}
	}
    );
	
	/*if(location.hash && location.hash.search(/#table_/) > -1)
	{
		$$('table[id^=table_teil]').invoke('hide');
		$$('span[id^=table_minplus_]').each(function(s){
		$(s).removeClassName('table_minus');
		$(s).addClassName('table_plus');
		});

		var firmaid = location.hash.replace(/#table_/, '');
		console.log(firmaid);
		showtable(firmaid);
	}*/
}
);


/*
var version = parseFloat(navigator.appVersion.split('MSIE')[1]);
if ((version >= 5.5) && (version < 7) && (document.body.filters)) {
document.getElementsByClassName('ie-fix-opacity').each(function(poElement){
// if IE5.5+ on win32, then display PNGs with AlphaImageLoader
var cBGImg = poElement.currentStyle.backgroundImage;
var cImage = cBGImg.substring(cBGImg.indexOf('"') + 1, cBGImg.lastIndexOf('"'));
poElement.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + cImage + "', sizingMethod='scale')";
poElement.style.backgroundImage = "none";
});
}
*/