//alert = console.info; // Alle alerts werden in Firebug umgeleitet.

function show_message(message){
    if(!message){
        message = tmp_message;
    }
    if(window.pageYOffset){
       $('alert').style.bottom = "-"+window.pageYOffset +"px";
    }
    else{
        $('alert').style.bottom = "-"+document.documentElement.scrollTop +"px";
    }
    if(message.length > 0){
        var close_button =' <input type="button" value="'+jsCloseButton+'" onclick="Effect.BlindUp(\'alert\',{duration:0.4})">';
        Element.update('alert',message+""+close_button);
        Effect.BlindDown('alert',{duration:0.3});
        window.setTimeout("Effect.BlindUp('alert',{duration:0.4})",10000);
    }
};


function goToCat(id,count){
    if(count == 0){
        show_message(keine_eintraege)
    }
	if(count == 1){
	 location.href = "?page=edit-entry&aIdEntry="+ id;
	}
	if(count > 1){
	   location.href = "?page=entries&aIdCategory="+ id;
	}
	
	
}

var cat_liste = new Array(); 

function inThisCategory(catID,bez){

if(cat_liste.indexOf(catID) != '-1'){
    cat_liste.splice(cat_liste.indexOf(catID),cat_liste.indexOf(catID)+1)
}
else{

    cat_liste[cat_liste.length]=catID;
}
cat_liste = cat_liste.uniq();

$('aParent').value = cat_liste;
alert(bez);
alert(cat_liste);
}

function toggleAgenturInfos(id,anzahl_agenturen){
for(var x=1;x<anzahl_agenturen+1;x++){
    Element.hide('agentur_'+x);
}
Element.show('agentur_'+id);
}

function submit_user_delete(){
    $('updateuser').action ="?page=user-delete";
    $('updateuser').submit();
}

///
function dualSelect(from, to,type) {
    from = $(from);
    to = $(to);
    
    var i = 0;
    var opt;
    var counter = from.options.length;
    
    refreshCatList = false;    
    while (i < counter) {
    
        if (from.options[i].selected && from.options[i].disabled == false) {
            
            opt = new Option(from.options[i].text.replace(/-/gi,''), from.options[i].value);
            opt.dblclick =function(){ ondblclick="dualSelect('aParentCat','aSubcats',0)";}                        
            if(type == 1){
                try {
                    to.add(opt, null);
                }
                catch (ex) {
                    to.add(opt);
                }
                //from.remove(i);
               from.options[i].disabled=true;
               
            }
            
            if(type == 0){
                from.remove(i);
                refreshCatList = true
                counter--;
            }
            
           
            continue;
           
        }
         i++;
        
    }
    
    updateaParentCatHidden();
    if(refreshCatList == true){
        getSubCats();
    }
}
///

function updateaParentCatHidden(){
 $('aParentCatHidden').value="";
    for(x=0;x<$('aParentCat').options.length;x++){
        $('aParentCatHidden').value += ','+$('aParentCat').options[x].value;
    }
    $('aParentCatHidden').value = $('aParentCatHidden').value.substring(1,$('aParentCatHidden').value.length);

}

function getSubCats(){
parentCat = $('aTopCat').options[$('aTopCat').selectedIndex].value;
var selectedCats = $('aParentCatHidden').value;
    subCats = new Ajax.Request('system/inc/functions/fCallbackSubCats.cfm?aParentCat='+parentCat+'&aSelectedCats='+selectedCats,{
        onComplete:function(req){
            $('select_subcats').update(req.responseText); 
        }
    })
}


function deleteEntry(aIdEntry){
		 var ask = prompt(jsEintragLoeschen,"")
		  if(ask){
		      ask = ask.toLowerCase();
		  
            if(ask.indexOf('ja') != -1 || ask.indexOf('yes') != -1){
                document.location.href="index.cfm?page=entry-delete&aIDEntry="+aIdEntry;
            }
            else{
              show_message(jsFalscheEingabe);
            }
		}
}
function wrapText(ele,pixels){
		suff= "...";
		
		count = 0;
		while(Element.getDimensions(ele).width >= pixels){
		count=1;
		var tmp = $(ele).innerHTML.substring(0,$(ele).innerHTML.length-suff.length-1);
		  $(ele).innerHTML = tmp+suff;
		}
		if(count == 1){
		  $(ele).innerHTML = tmp+suff;
		}
		
		
}

function activateOpenCloseTime(frage){
    if(confirm(frage)){
        $('tr_freischalten').show();
        $('button_freischalten').hide();
    }

}

function paging(parameter,val,max_page){
    if(val <= max_page && val >=1){
    
    location.href ="index.cfm?"+parameter+"="+val;
    
    
    }else{
        alert('Bitte geben Sie eine g\u00fcltige Seitenzahl an (1 - '+max_page+')');
    }

}


