

   // check if CKEDITOR Object exist
function ifCkeditor()
{
     variable = 'CKEDITOR';
    return (typeof(window[variable]) == "undefined")?  false: true;
} 








activeElement = null;
activeElementName = "";




////////////////////////
function showCssBox(com, element) {
    
    $('body').append('<div id="css_box"></div>');           
    //url = '/code/wizzard/insert_html_source_code.php';
//    url = '/snapol/wizzard/css_box.html';
    url = "/snapol/js_php/getProperty.php?com="+com;
    
    
    activeElement = $(element);
    activeElementName = element;
    
    
    $("#css_box").load(url, function() {
                           //width:800,
    
                 //alert("loaded");
                 
                  // EVENT für Änderungen
               /*     $(".snapol_property").change(function() {
  
                     alert("hello world");
                     alert($(this).attr('name'));
                     alert($(this).val());
                     
                     
                    });   */
                 
    
    });    
}




function changeCssAttribute(attribute, value) {
    

    //alert(activeElementName);


    //$('body').css('background-color', $('#prop_background_color').val());"
    $(activeElement).css(attribute, value);
    
    //css_class = $(activeElement)
    
    $.get("/snapol/js_php/changeCssProperty.php", { css_class: activeElementName, attribute: attribute, value: value },
   function(data){
   
       //if (data)
         alert("Data Loaded: " + data);
   });
    
    
    
    
}




function closeCssBox() {

  $("#css_box").remove();  
    
}













function showFunctionEditor()
        {
        $('body').append('<div id="dialogFunctionEditor"></div> ');
        //php_property gibt probleme

        id2 = $(activeElement).attr('click');
        //alert(id2);
        
        // falls noch kein element vorhanden
        if (id2 == undefined) {
            
            id2 = $.ajax({
                url: "/snapol/js_php/createHtmlValue.php",
                async: false
            }).responseText;
          
          //alert(id2);      
          $(activeElement).attr('click', id2);     
   
        } 

        url = '/code/wizzard/function_editor.php?table=_html&id2=' + id2;

        $("#dialogFunctionEditor").load(url).dialog({ title: "Function Editor", modal: true, height: 700, width: 800,
                                                      buttons: { "Ok": function()
            {


            // speichern   
            html = $("#function_code").html();
            //id2 = $("#function_id2").val();
            //alert(id2);
            
            saveHtmlValue(id2, html);

            /* $.post("/snapol/editor/saveHtmlContent.php", { id2: id2, html: html }, function(data){
              
                     //alert("Data Loaded: " + data);
         
            });  */

            //alert("close");


            //alert(html);


            // Dialog Box schliessen
            //$("#dialogFunctionEditor").dialog("close");
            $(this).dialog("close");
            $(this).remove();
            //alert("close2");  

            }
        }
        });
        }
        
        
        
        
        
        
        
        function showHtmlEditor() {
            
         
    
    $('body').append('<div id="dialogHtmlEditor"></div>');           
    url = '/code/wizzard/html_editor.php';

    $("#dialogHtmlEditor").load(url, function() {
             
             $("#wysiwyg_editor").val($(activeElement).html());
                           
    }).dialog({modal:true, buttons: { "Ok": function() { 
            
        alert($("#wysiwyg_editor").val());     
        
        $(activeElement).html($("#wysiwyg_editor").val()); 
             $(this).dialog("close");
             $(this).remove();
    }},
});    
}





function showTableWizzard() {
    
    $('body').append('<div id="dialogBox"></div>');           
    url = '/code/wizzard/table_wizzard.php';

    $("#dialogBox").load(url, function() {
                           
    }).dialog({modal:true, buttons: { "Ok": function() { 
            
             html = changeTable();
             $(activeElement).html(html); 
             $(activeElement, "tbody").attr("table", $("#table_value").val());
             $(this).dialog("close");
             $(this).remove();
    }},
});    
}





////////////////////////
function showAddFieldWizzard() {
    
    $('body').append('<div id="dialogBox"></div>');           
    
    table = $(activeElement, "tbody").attr("table");  
    url = '/code/wizzard/add_table_field.php?table='+table;
    $("#dialogBox").load(url, function() {
                           //width:800,
    }).dialog({modal:true, buttons: { "Ok": function() { 
        
             //alert($("#"+elementId).html());
             //html = insertDatabaseForm();
             
           /*  html = $("#html_code").val();
             //alert(html);
             //$("#editor").append(html);                     
             
              if (propertyModus) {
        
      //  alert("active modus"); 
            $(activeElement).append(html);  
           
       } else {
       
             $("#snapol_editor").append(html);   

       }  */
             
             
             
             
    //strHeader = '<tr>';
    //strBody =  '<tr>';
    strHeader = '';
    strBody =  '';    
    
    
    
    $(".db_field").each(function(index) {
       
    
        
        if ($(this).attr('checked')) {
        
                                    field = $(this).attr("name");
                                    fieldText = field;
                                    fieldText = fieldText.replace(/_/ig, " ");
                                        
                                    strHeader = strHeader + '<th id="wizzard_header_'+field+'">'+fieldText+'</th>';
                                        
                                        
                                    tmp = '['+field+']';
                                        
                                        
                                    //if ($("#image_"+field+":checked").val() !== null) {
                                    if ($("#image_"+field).attr('checked')) {    
                                            //tmp = '<img src="['+field+']" width="10" height="10" />';
                                            tmp = '<img src="['+field+']" width="" height="" />';         
                                    }
                                        
                                    if ($("#link_"+field).attr('checked')) {    
                                            tmp = '<a href="['+field+']">['+field+']</a>';
                                    }
                                        
                                        
                                        
                                        
                                        
                                     strBody =  strBody + '<td id="wizzard_field_'+field+'">'+tmp+'</td>';                                    
            
            
        }
    });    
    
    //strHeader = strHeader + '</tr>';
    //strBody =  strBody + '</tr>';   
    
    
    
    //$(activeElement, "thead tr").append(strHeader);
    
    
    $(activeElement).children("thead").children("tr").append(strHeader);  
    $(activeElement).children("tbody").children("tr").append(strBody);  
    
   /* $(activeElement, "thead tr").append(strHeader);
    alert(strHeader);    
    
    $(activeElement, "tbody tr").append(strBody);  
    alert(strBody); */
    
    
    //html = '<thead><tr>'+strHeader+'</tr></thead><tbody com="data" table="'+table+'" orderby="'+orderby+'" limit="'+limit+'" filter_mygroup="">'+strBody+'</tbody>';        
    //alert(html);
             
    $(this).dialog("close");
    $(this).remove();

    }},
});    
}



function showAddDetailView() {
    
    table = $(activeElement, "tbody").attr("table");     
    
    strHeader = '<th>&nbsp;</th>';
    strBody = '<td><a href="" com_href="data_detail_view" table="'+table+'" id2="[id2]">Detail</a></td>';
    
    $(activeElement).children("thead").children("tr").append(strHeader);  
    $(activeElement).children("tbody").children("tr").append(strBody);  
   
}







function showAddDelete() {
    
    table = $(activeElement, "tbody").attr("table");     
    
    strHeader = '<th>&nbsp;</th>';
    strBody = '<td><a href="" com_href="data_delete" table="'+table+'" id2="[id2]">loeschen</a></td>';
    
    $(activeElement).children("thead").children("tr").append(strHeader);  
    $(activeElement).children("tbody").children("tr").append(strBody);  
   
}





////////////////////////
function showHtmlCodeWizzard() {
    
    $('body').append('<div id="dialogBox"></div>');           
    url = '/code/wizzard/insert_html_source_code.php';
    $("#dialogBox").load(url, function() {
                           //width:800,
    }).dialog({modal:true, buttons: { "Ok": function() { 
        
             //alert($("#"+elementId).html());
             //html = insertDatabaseForm();
             
             html = $("#html_code").val();
             //alert(html);
             //$("#editor").append(html);                     
             
             
             if (ifCkeditor()) {
                //insertText(html);
//                alert(html);
                CKEDITOR.instances.ckeditor_id.insertHtml(html);
//                CKEDITOR.instances.ckeditor_id.insertText(html);

                
                
            } else {
                //$("#editor").append(html);     
            
                if (propertyModus) {
        
      //  alert("active modus"); 
            $(activeElement).append(html);  
           
       } else {
       
             $("#snapol_editor").append(html);   

       }
            
            
            }
             
             
        
             
             
             
             $(this).dialog("close");

    }},
});    
}














////////////////////////
function showInsertCom() {
    
    $('body').append('<div id="dialogBox"></div>');           
    url = '/code/wizzard/insert_com.php';
    $("#dialogBox").load(url, function() {
                           //width:800,
    }).dialog({modal:true, buttons: { "Ok": function() { 
        
             //alert($("#"+elementId).html());
             //html = insertDatabaseForm();
             
             com = $("#wizzard_com_list").val();
             type = "body";
             
             
             getComUrl = '/snapol/js_php/getCom.php?com='+com+'&type='+type;
             
             alert(getComUrl);
//url = '[php_script]?com='+com+'&type='+type; 

//alert(url);

//tmpActiveElementModus = activeElementModus;

$.get(getComUrl, function(data) {
  
          
    
    CKEDITOR.instances.ckeditor_id.insertHtml(data);      
     
    
});
             
             
             $(this).dialog("close");

    }},
});    
}















function showSortEditor() {
    
    tmpElement = activeElement;

    
    url = '/code/wizzard/sort_editor.php';

    
    $('body').append('<div id="dialogBox"></div>');    
    
    
    
    $("#dialogBox").load(url, function() {
    

        $("#sort_editor").sortable();
        $("#sort_editor").html($(tmpElement).html());
    
                           //width:800,
    }).dialog({modal:true, buttons: { "Ok": function() { 
        
                 
             
             $(tmpElement).html($("#sort_editor").html());             
             $(this).dialog("close");
             
    }},
});   
}










function showCssWizzard() {
    
    
    
    
    
}





function showRegexWizzard() {
    
    
    
    
}




function showFileBrowser() {
    
    
    
    
}








