/*********************************************************************
**	MOOTOOLS - AJAX funkcija za inicijalizaciju 					**
**	XMLHTTPRequest objekta 											**
**																	**
**	$link - ajax skripta koja vraca response						**	
**	$metoda - get ili post metoda									**	
**	$id		- handler objekta gdje vracam response					**	
**********************************************************************/	


	var AJAX = function(link,metoda,id){
	
		var myAjaxRequest1 = new Request({
		
		url: link,
		method: metoda, 
		

		/** salje podatke kao parametar $key=$value **/
		//data: { 'title' : 'Odgovor' },

		/*
		onSuccess when the instance receives a successful response from the server
		onSuccess: function(responseText, responseXML){
		Empty the log and show the spinning indicator.
		var log = $('log_res').empty().addClass('ajax-loading');
		*/
		
		onSuccess: function(responseText, responseXML){
			$(id).removeClass('ajax-loading');
			$(id).innerHTML =  responseText;
			
			/*
			*
			* Ovdje pozivaj JavaScript F-je nakon ajax responsa
			*
	 		*/


			
		} 		
	 	}); 
	 	
	 	/*
	 		onComplete: function(response) { 
				log.removeClass('ajax-loading');
				log.set('html', response);
			}});	
	 	*/
	 	
	 	return 	myAjaxRequest1;	
	};

/*********************************************************************
**	MOOTOOLS - Funkcija load and show popup window					**
**	XMLHTTPRequest objekta 											**
**																	**
**	$link - ajax skripta koja vraca response						**
**	$triger - id elementa na koji se okida akcija					**		
**	$metoda - get ili post metoda									**	
**	$id		- handler objekta gdje vracam response					**	
**********************************************************************/	

// prikazi popup bez trigera
var show = function(){
	
		$('fb-modal').setStyles({
			opacity:0,
			display:'block'
		});
	
		/* hiders */
		$('fb-close').addEvent('click',function(e) { 
		
		$('fb-modal').fade('out');		
			// refresha stranicu nakon sto zatvorimo popup
			window.location.reload(true); 
		});
	
		window.addEvent('keypress',function(e) { if(e.key == 'esc') { $('fb-modal').fade('out'); } });


	
	
	
	};

// prikazi popup sa trigerom na koji okidam popup
	var showPopUp = function(link,triger){
	
		
		$('fb-modal').setStyles({
			opacity:0,
			display:'block'
		});
	
		/* hiders */
		$('fb-close').addEvent('click',function(e) { 
		
		$('fb-modal').fade('out');		
			// refresha stranicu nakon sto zatvorimo popup
			window.location.reload(true); 
		});
	
		window.addEvent('keypress',function(e) { if(e.key == 'esc') { $('fb-modal').fade('out'); } });

		/* click to show */
		$(triger).addEvent('click',function() {
		
			$('fb-modal').fade('in');	

			//$('dialog_body').load('../index.php/clanica/displayAddClanicaForm');
			$('dialog_body').load(link);
			
		});
	
	
	
	
	};
	
/**********************************************************************************
**	OmniGrid - Advanced DataGrid for Mootools   								 **
**  http://www.omnisdata.com/omnigrid/                       					 **
**	Advanced DataGrid for Mootools 												 **
**				**	
**				**	
**				**	
***********************************************************************************/	
    
    /** omnigrid - onselect row **/
    function onGridSelect(evt)
    {
    }
    
    var cmu = [

		  
			{ 
			   header: "id",
			   dataIndex: 'id',
			   dataType:'number',
			   hidden: true,
			   width:10
			},
		
            {
               header: "Korisnik",
               dataIndex: 'korisnik',
               dataType:'string',
               width:100
            },
            {
               header: "Akcija",
               dataIndex: 'akcija',
               dataType:'string',
               width:260
               
            },
            {
               header: "Opis",
               dataIndex: 'opis',
               dataType:'string',              
               width:240
            },  
            {
               header: "Vrijeme",
               dataIndex: 'datum',
               dataType:'date',
               width:121
            }];	
	
	var tableGear =  function(url,param){
				
		datagrid = new omniGrid('logovi', {
	        columnModel: cmu,
	       /* buttons : [
	          {name: 'Add', bclass: 'add', onclick : gridButtonClick},
	          {name: 'Delete', bclass: 'delete', onclick : gridButtonClick},
	          {separator: true},
	          {name: 'Duplicate', bclass: 'duplicate', onclick : gridButtonClick}
	        ],*/
	        url:url,
	        perPageOptions: [10,20,50,100,200],
	        perPage:20,
	        page:1,
	        pagination:true,
	        serverSort:true,
	        showHeader: true,
	        alternaterows: true,
	        showHeader:true,
	        sortHeader:true,               
	        resizeColumns:true,
	        multipleSelection:true,
	        // slanje parametra
	       // parameter:param,
	        
	        // uncomment this if you want accordion behavior for every row
	        /*
	        accordion:true,
	        accordionRenderer:accordionFunction,
	        autoSectionToggle:false,
	        */
			
			/*
			*
			* 759: li.setStyle('width',
			*
			* hDivBox.setStyle(' Line: 979
			*
			* var columns = el.getElements('div.td');
			
			* Response: setData: function(data, cm){
			*
			* Iskipaj podatke: 	renderData: function(){
			*/
				
	        //width:816,
	        width:740,
	        height: 560
	    });
	    
	    //datagrid.addEvent('click', onGridSelect);
	
	};
	


/****************************************************************************************
**																					   **				
** Contains the window Event 'domready', which will execute when the DOM has loaded.   **
**																					   **	
*****************************************************************************************/
window.addEvent('domready', function(){

	 if ($('username')) 
	 {
	 	if( $('username').get('value') ){
	 		$('password').focus();
	 	}else{
			$('username').focus();
		}
	 }

	if ($('passwordForm'))
	{
		$('passwordForm').addEvent('submit', function(e) {
			//Prevents the default submit event from loading a new page.
			
			e.stop();
			//Empty the log and show the spinning indicator.
			var log = $('log_res').empty().addClass('ajax-loading');
			//Set the options of the form's Request handler. 
			//("this" refers to the $('myForm') element).
			this.set('send', {onComplete: function(response) { 
				log.removeClass('ajax-loading');
				log.set('html', response);
			}});
			//Send the form.
			this.send();
			
		});
	
	}
		
	
	
	
	
	if ($('logovi')){

			/****************************************
			* TABLE GEAR
			* Request.JSON
			* posalji parametar za AJAX akriptu	
			****************************************/
			//data - (string: defaults to '') The default data for Request:send, used when no data is given.
			// OMNIGRID.JS : LINE: 327 data = {page:this.options.page, perpage:this.options.perPage, };
            //var parametar = IDkartice;
            var parametar = '';
            

 			var host = window.location.hostname
 			//'http://'+host+'
          	// alert(window.location.hostname);
            
            // var url = "http://www.cix.hr/cix/index.php/logovi/showLogs";
            var url = 'http://'+host+'/cix/index.php/logovi/showLogs';  
             
            // alert (url);        			
			tableGear (url, parametar);

	}



});	
	
