function csv_attribute(id,name,sid){
    var popup = $('m12_popup');
    var close = '<a href="javascript:disablecsv_attribute()">close</a>';
    var replacement = '<div id="m12_popup">';
    replacement = replacement+'<br>'+close;
    replacement = replacement+'</div>';
    popup.replace(replacement);
    $('m12_popup').setStyle({ display:'block' }); 
    new Ajax.Updater("m12_popup", "/universal/ajax.php?action=formid&var[]="+id+"&var[]="+encodeURIComponent(name)+"&sessid="+sid, {asynchronous:true,evalJS:true,insertion:Insertion.Top});
}
function disablecsv_attribute(){
    var popup = $('m12_popup');
    popup.setStyle({ display:'none' }); 
    var replacement = '<div id="m12_popup"></div>';
    popup.replace(replacement);
}
function m12aufzu(ind){
    var child = $(ind).childElements();
    var indimg = ind.replace(/am_/,"m12impl_");
    var sstat = $(indimg).readAttribute('status');
    child.each(function(s) {
	if(s.readAttribute('id')!=""&&s.nodeName=="DIV"){	
	    if(sstat == "plus")s.style.display="block";// s.show();
	    else s.hide();
        }
     });
     if(sstat == "plus"){
	$(indimg).setAttribute("status","minus");
	srcstring = $(indimg).readAttribute('src');
	srcstring = srcstring.replace(/plus/,"minus");
	$(indimg).setAttribute("src",srcstring);
     }
     else{
	$(indimg).setAttribute("status","plus");
	srcstring = $(indimg).readAttribute('src');
	srcstring = srcstring.replace(/minus/,"plus");
	$(indimg).setAttribute("src",srcstring);     
     }
}
function aufzu(ind){
    var sstat = $(ind).style.display;
    if(sstat != "block"){
	$(ind).style.display="block";
    }
    else{
	$(ind).hide();
    }
}
function dropthis(eleid){
    Droppables.add(eleid, {accept:'csvmenue', hoverclass:'am_kcc_csvhover', onDrop:function(element){dropdown(eleid,element.id)}})
}
function dropdowntemp(kccid,csvid){
    alert(kccid+":"+csvid);
    /*
    childs = $(kccid).childElements();
    childs.each(function(s) {
	if(s.tagName=="IMG"){
	    var csvinh = $(csvid).firstChild;
	    s.setAttribute("src",csvinh.readAttribute('src'));
	    s.nextSibling.data = csvinh.nextSibling.data;
	}
    });
    */
}
function dropdown(kccid,csvid){
    childs = $(kccid).childElements();
    childs.each(function(s) {
	if(s.tagName=="IMG"){
	    var csvinh = $(csvid).firstChild;
	    s.setAttribute("src",csvinh.readAttribute('src'));
	    s.nextSibling.data = csvinh.nextSibling.data;
	}
    });
}
function replAttr(node,attribute,regex,ersatz){
    if(node.readAttribute(attribute)!=""){
	var at = node.readAttribute(attribute);
	at = at.replace(regex,ersatz);
	node.setAttribute(attribute,at);
    }
    return node;
}
function jo_dropactivated(de){
    jo_temp_active = de;
    var deel = de.element;
    var deid = deel.readAttribute("id");
    var ances = deel.ancestors();
    if(typeof ances != undefined){
        var parentdeid = ances[0].readAttribute("id");
        /* Knoten duplizieren und vor menueknoten einsetzen*/
        var nodebefore = $(parentdeid).cloneNode(true);
        replAttr(nodebefore,"id",/_[0-9]+/,"_tempb");
        var nchild = nodebefore.childElements();
        nchild.each(function(s){
    	    if(s.readAttribute('id'))replAttr(s,"id",/_[0-9]+/,"_tempa");
    	    if(s.nodeName=="A") s.replace('<img src="/gfx/icon_m12_pl.gif" class="m12davor_img">');
	    if(s.nodeName=="DIV")s.remove();
	    if(s.nodeName=="SPAN"){
		var spaninh = s.firstChild;
		spaninh.setAttribute("src","/gfx/icon_m12_blank.gif");
		spaninh.nextSibling.data = "Neuer Menuepunkt";
		s.style.backgroundColor = "#FF9933";
	    }
	    /*
	    if(s.nodeName=="SCRIPT"){
		var newsrcipt = '<script type="text/javascript">\n';
		newsrcipt = '//<![CDATA[\n';
		newsrcipt = 'Droppables.add("am_kcc_span_tempb", {accept:'+String.fromCharCode(39)+'csvmenue'+String.fromCharCode(39)+', hoverclass:'+String.fromCharCode(39)+'am_kcc_csvhover'+String.fromCharCode(39)+', onDrop:function(element){dropdowntemp("am_kcc_span_tempb",element.id),new Ajax.Updater("am_kcc_span_tempb", "/universal/ajax.php", {asynchronous:true,evalJS:true,insertion:Insertion.Bottom});}});\n';
		newsrcipt = '//]]>\n';
		newsrcipt = '</script>\n';
		s.replace(newsrcipt);
	    }
	    */
	});
	$(parentdeid).insert({before:nodebefore});
	
	//Droppables.add("am_kcc_span_tempb", {accept:'csvmenue', hoverclass:'am_kcc_csvhover', onDrop:function(element){dropdowntemp("am_kcc_span_tempb",Draggables.activeDraggable.element.id),new Ajax.Updater("am_kcc_span_tempb", "/universal/ajax.php", {asynchronous:true,evalJS:true,insertion:Insertion.Bottom});}});
        
	/* Knoten duplizieren und nach menueknoten einsetzen*/
	var nodeafter = $(parentdeid).cloneNode(true);
	replAttr(nodeafter,"id",/_[0-9]+/,"_tempa");
	var nchild = nodeafter.childElements();
	nchild.each(function(s){
	    if(s.readAttribute('id'))replAttr(s,"id",/_[0-9]+/,"_tempa");
	    if(s.nodeName=="A") s.replace('<img src="/gfx/icon_m12_pl.gif" class="m12davor_img">');
	    if(s.nodeName=="DIV")s.remove();
	    if(s.nodeName=="SPAN"){
		var spaninh = s.firstChild;
		spaninh.setAttribute("src","/gfx/icon_m12_blank.gif");
		spaninh.nextSibling.data = "Neuer Menuepunkt";
		s.style.backgroundColor = "#FF9933";
	    }
	    /*
	    if(s.nodeName=="SCRIPT"){
		var newsrcipt = '<script type="text/javascript">\n';
		newsrcipt = '//<![CDATA[\n';
		newsrcipt = 'Droppables.add("am_kcc_span_tempa", {accept:'+String.fromCharCode(39)+'csvmenue'+String.fromCharCode(39)+', hoverclass:'+String.fromCharCode(39)+'am_kcc_csvhover'+String.fromCharCode(39)+', onDrop:function(element){dropdowntemp("am_kcc_span_tempa",element.id),new Ajax.Updater("am_kcc_span_tempa", "/universal/ajax.php", {asynchronous:true,evalJS:true,insertion:Insertion.Bottom});}});\n';
		newsrcipt = '//]]>\n';
		newsrcipt = '</script>\n';
		s.replace(newsrcipt);
	    }
	    */
	});
	$(parentdeid).insert({after:nodeafter});
	Droppables.add("am_kcc_span_tempb", {accept:'csvmenue', onDrop:function(element){dropdowntemp("am_kcc_span_tempb",Draggables.activeDraggable.element.id);}});
	//alert($(parentdeid).nextSibling.readAttribute("id"));
  }
}
function jo_dropdeactivated(de){
    var deel = de.element;
    var deid = deel.readAttribute("id");
    //alert(deid);
    var ances = deel.ancestors();
    var parentdeid = ances[0].readAttribute("id");
    var tempida = parentdeid.replace(/_[0-9]+/,"tempa");
    var tempidb = parentdeid.replace(/_[0-9]+/,"tempb");
    //alert(deid);
    //$(tempida).remove();
    //$(tempidb).remove();
}
function mp_attributes(ele,formid,link,idnr,sprache){
    var url = '/universal/ajax_mp_edit.php?id='+ele+'&idnr='+idnr+'&formid='+formid+'&link='+link+'&sprache='+sprache; // notice the use of a proxy to circumvent the Same Origin Policy. 
    new Ajax.Request(url, {
	method: 'get',
	onSuccess: function(transport) {
	    $("am_kcc_root").insert({before:transport.responseText});
	} 
    });   
}