var grid;

window.onload = function(){
  if($("dataTable")){ 
    grid = mint.gui.CreateGridWidget("dataTable");
   
    grid.AddSortCells();
    grid.SetSelective();
   }
   
    if($("editor")){
	   
	           tinyMCE.init({
                    		// General options
                    		language : "pl",
                    		mode : "exact",
	                      elements : "editor",
	                      entity_encoding : "raw",
                    		theme : "advanced",
                    		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
                    
                    		// Theme options
                    		theme_advanced_buttons1 : "pagebreak,|,bold,italic,underline,strikethrough,|,cut,copy,pasteword,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontsizeselect",
                    		theme_advanced_buttons2 : "search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,code,|,insertdate,inserttime,preview,|,forecolor,backcolor,|,visualchars,nonbreaking,template",
                    		theme_advanced_buttons3 : "tablecontrols,|,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,|,print,|,ltr,rtl,|,fullscreen",
                    		theme_advanced_toolbar_location : "top",
                    		theme_advanced_toolbar_align : "left",
                    		theme_advanced_statusbar_location : "bottom",
                    		theme_advanced_resizing : true,
                    
                    	  });   

	} 
   
} 

function show(url){

        $("option").show();
         
        var req = mint.Request();
        req.OnSuccess = function() {
                 $("option").innerHTML = this.responseText+" <div class=\"showCloseLink\"><a href=\"javascript: showClose();\"><b>Zamknij okno (X)</b></a></div>";
        }

        req.Send(url);
}

function showClose(){

        $("option").hide();
        $("option").innerHTML = " ";
        
}

function sendFormOption() {      
    
    var reqEdit = mint.Request();

    $("option").show();      
            
    reqEdit.OnSuccess = function() {
            $("option").innerHTML = this.responseText+" <div class=\"showCloseLink\"><a href=\"javascript: showClose();\"><b>Zamknij okno (X)</b></a></div>";      
    }
                
    reqEdit.SendForm("form");
    
}           

function removeTr(id){

    mint.fx.Color('tr'+id, "backgroundColor", "#ffff00", "#ffffff", 20, 400, null, function(){$('tr'+id).hide();});

}

function deleteTable(id){

    mint.fx.Color('news'+id, "backgroundColor", "#ffff00", "#ffffff", 20, 400, null, function(){$('news'+id).hide();});

}

function hightlightTr(id, color){

    if(color==0) $('tr'+id).style.backgroundColor = "#ff6666";
    if(color==1) $('tr'+id).style.backgroundColor = "#ffffff";

}

function saveContent(date) {      
    
    tinyMCE.get('editor').hide();
    var reqEdit = mint.Request();
            
    reqEdit.OnSuccess = function() {
        var data = new Date();
				var Year = data.getYear();
				Year += 1900;
        if(date) $("dateEdit").innerHTML = data.getDate()+"."+data.getMonth()+"."+Year+" "+data.getHours()+":"+data.getMinutes()+":"+data.getSeconds();
        $("option").show(); 
        $("option").innerHTML = this.responseText+" <div class=\"showCloseLink\"><a href=\"javascript: showClose();\"><b>Zamknij okno (X)</b></a></div>";     
        tinyMCE.get('editor').show();
    }
                
    reqEdit.SendForm("form");
    
}

