/*******************************************************************************
	Filename		: shared.js

	Created			: Mittwoch, 6. Februar 2008 (15:31:19)
	Created by		: Markus Braunschweiler

	Last Updated	: Donnerstag, 17. April 2008 (11:00:03)
	Updated by		: fluristefan

	Comments		: allgemeine js funktionen für die weblics
*******************************************************************************/

/*
 KATEGORIEN EDITIEREN
 @param: id = Kategorie-ID
 @param: text = Kategoriename
*/

function editKat(id,text){
    var cmd = "ek";
    if (id < 1){
        check = prompt("Kategorie erstellen", text);
        cmd = "nk";
    }
    else{
        check = prompt("Kategorie editieren", text);
    }
    if(check){
        //alert("sollte jetzt speichern...");
        document.location.href = "kategorien.php?c="+cmd+"&k="+id+"&t="+check;
    }
    else{
        //document.location.reload();
    }
}

/*
 ORTE EDITIEREN
 @param: id = Ort-ID
 @param: text = Ortsname
*/

function editOrt(id,text){
    var cmd = "eo";
    if (id < 1){
        check = prompt("Ort erstellen", text);
        cmd = "newOrt";
    }
    else{
        check = prompt("Ort editieren", text);
    }
    if(check){
        document.location.href = "orte.php?c="+cmd+"&o="+id+"&t="+check;
    }
    
}

/*
 MODULSUCHE STARTEN
 @param: term = Suchbegriff
 @param: kat = Kategorie
 @param event = blank|Submit
*/

function vsuche(term,kat,event){
    if(term.length > 2){
        loadContentAjax(term,kat);
    }
    if (event == "submit" && (term == "" || term.length < 3)) {
      alert("Bitte geben Sie einen gültigen mindestens 3 Zeichen langen Suchbegriff ein!");
    } 
}

/*
 SUCHCONTAINER LESEN
 Lädt dynamisch den Suchseite in den entsprechenden Container. 
 Parameter werden via vsuche übergeben!
 @param: t = Term
 @param: k = Kategorie
*/

function loadContentAjax(t,k){
    wGetUrlAjax('suche_ajax.php?t='+t+'&k='+k, loadContentAjaxResponse);
}

function loadContentAjaxResponse(responseText){
    wEmbedString('searchresults', responseText);
}






function loadOnChange(url){
    document.location.href = url;
}

function IncludeJavaScript(jsFile)
{
  document.write('<script type="text/javascript" src="'
    + jsFile + '"></script>');
}

//IncludeJavaScript('/weblication/grid/taglib/wgl/scripts/wGui.js');

function loadDynContent(div, url){
    wEmbedString(div, wGetUrlAjax(url, this));
    
}


function fileselector_a_href_onSelect(file){
    var value = document.getElementById('onlineformular').value;
    var regex = /\(('|")(.*)('|").*('|")(.*)('|").*('|")(.*)('|").*\)/;
    match = value.match(regex);
    if(match){
    	width		= match[5];
    	height 	= match[8];
    	document.getElementById('onlineformular').value = "javaScript:wPopUp('"+file+"', '"+width+"', '"+height+"');";
    }
    else{
    	document.getElementById('onlineformular').value = file;
    }
    document.getElementById('onlineformular').value = file.replace(document.getElementById('rep').value,'');
}
                      
function openSelektor(pfad,element){
    //showMaskGetUrl_a_href();
//    fns_openPopup("/weblication/grid/scripts/wEditor.php?action=showmaskeditlink&path="+pfad+"&nodeType=text");

    var path = pfad;
    var context = pfad;
    if(path == ''){
      path = document.getElementById('onlineformular').value;
    }
    //path = path.replace(/#.*/, '');
    path = encodeURIComponent(path);
    var url = '/weblication/grid/scripts/wFileselector.php?action=&path=' + path + '&context='+context+'&dirtype=standard&id=a_href';
    openWin(url, 'wSmartbrowser', 840, 540);
}

function editAbfallTermine(id,text) {
  var cmd = "nt";
  check = prompt("Termin erstellen\nBeispiel: DD.MM.YYYY oder DD.MM.YY")
  if (check && check.length > 6 && check.indexOf("..")) {
    document.location.href = "edit.php?c="+cmd+"&i="+id+"&t="+check;
  }
  else {
    alert ("Ungültiges Datum\nBitte erfassen Sie Datum nach Muster DD.MM.YYYY oder DD.MM.YY");
    }
  }

function showPDF(){
    var url= window.location;
    url = url+"&viewmode=print";
    //alert(url);
    window.open("/format/plugins/pdf/pdf.php?pdf=1&url="+url,screen.width,screen.height);
}
