<script type="text/javascript">

jQuery(document).ready(function($){
    //create the main events and their details from json
    var main_event_object = {
        getAllMainEvents: function(){
            return <?=$main_events_json?>;
        },
        getMainEventByID: function(event_main_id){
            var main_events = this.getAllMainEvents();
            var len = main_events.length;
            
            for(var i = 0; i < len; i++){
                if(main_events[i].event_main_id == event_main_id){
                    return main_events[i];
                }
            }
            
            return false;
        }
    };
    
    //open and close events for the lists
    $('.open-closer').click(function(){
        $(this).parent('div').parent('li').next('ul').toggle();
    });
    
    $('.open-closer-all').click(function(){
        $('.registrations').toggle();
        $('.events').toggle();
    });
    
    $('.open-closer-allin').click(function(){
        $('.registrations').fadeIn();
        $('.events').fadeIn();
    });
    
    $('.open-closer-allout').click(function(){
        $('.registrations').fadeOut();
        $('.events').fadeOut();
    });
    
   
    //create the edit event dialog
    $('#edit_event_dialog').dialog({
        autoOpen: false,
        modal: true,
        width: 400,
        buttons: {
            'Módosítás': function(){
                $('#modositas_form').submit();
                $('#edit_event_dialog').dialog('close');
            },
            'Mégsem': function(){
                $('#edit_event_dialog').dialog('close');
            }
        }
    });
    
    
    //confirm the delete links
    $('.del_anchor').click(function(){
        var href = $(this).attr('href');
        var question = $(this).attr('question');
        
        //create the confirm dialog
        $('#confirm_dialog').dialog({
            autoOpen: false,
            modal: true,
            buttons: {
                'Törlés': function(){
                    window.location = href;
                },
                'Mégsem': function(){
                    $('#confirm_dialog').dialog('destroy');
                }
            }
        }).html(question).dialog('open');
        
        return false;
    });
    
    
    //edit the event details
    $('.edit_anchor').click(function(){
        //populate the dialog
        var con = $('#modositas_form');
        var event = $(this).parents('.event');
        
        $('#event_id', con).val(event.attr('event_id'));
        $('#event_main_id', con).val(event.attr('event_main_id'));
        $('#nev_hun', con).val(event.attr('event_name'));
        $('#nev_eng', con).val(event.attr('event_name_eng'));
        $('#dlid', con).val(event.attr('dl_id'));
        
        $('#tipus option', con).each(function(){
			if($(this).text() == event.attr('tipus'))
				$(this).attr('selected','selected');
		});
        
        
        //open the dialog
        $('#edit_event_dialog').dialog('open');
        
        return false;
    });
    
    //create the new event dialog
    $('#new_event_dialog').dialog({
        autoOpen: false,
        modal: true,
        buttons: {
            'Rögzítés': function(){
                $('#rogzites_form').submit();
                $('#new_event_dialog').dialog('close');
            },
            'Mégsem': function(){
                $('#new_event_dialog').dialog('close');
            }
        }
    });
    
    //insert new event
    $('.new_anchor').click(function(){
        //populate the dialog
        var con = $('#rogzites_form');
        var event = $(this).parent('.new-link');
        
        $('#event_main_id_uj', con).val(event.attr('event_main_id'));
        
        //open the dialog
        $('#new_event_dialog').dialog('open');
        
        return false;
    });
    

    //edit the main event details
    $('.edit_main_anchor').click(function(){
        var event_main_id = $(this).parents('.main_event').attr('event_main_id');
        
        //open the dialog
        edit_main_event.clickEvent(event_main_id);
        
        return false;
    });
    
    //create the new main event dialog
    $('#new_main_event_dialog').dialog({
        autoOpen: false,
        modal: true,
        width: 800,
        buttons: {
            'Rögzítés': function(){
                $('#rogzites_main_form').submit();
                $('#new_main_event_dialog').dialog('close');
            },
            'Mégsem': function(){
                $('#new_main_event_dialog').dialog('close');
            }
        }
    });
    
    //create the click event handler for the new main event anchor
    $('.new_main_anchor').click(function(){
        var con = $('#rogzites_main_form');
        
        $('#weboldal_uj', con).bind('keyup blur click', function(){
            $(this).next('.view_link_container').children('a.view_link').attr('href', $(this).val());
        });
        
        //set the select link's target
        $('select', con).each(function(){
            $(this).next('.view_link_container').children('a.view_link').attr('href', '/page/show/'+$(this).val());
        }).change(function(){
            $(this).next('.view_link_container').children('a.view_link').attr('href', '/page/show/'+$(this).val());
        });
        
        $('#new_main_event_dialog').dialog('open');
        
        return false;
    });
    
    $('input[name^="datum"]').datepicker().datepicker('option', {dateFormat: 'yy-mm-dd', showButtonPanel: false , showOn: 'focus', showMonthAfterYear: false, showButtonPanel: true}, $.datepicker.regional['hu']);
    
    //set the numeric fields
    $('.numeric').numeric();
});

</script>
<style type="text/css">

ul.main_events, ul.events, ul.registrations{
    list-style-type: none;
    padding: 0px;
}

ul.main_events, ul.events{
    margin: 0px 0px 0px 20px;
}

ul.registrations{
    margin: 5px 0px 5px 40px;
}

li.main_event{
    font-weight: bold;
}

li.main_event, li.event{
    color: green;
    clear: both;
}

ul.events, ul.registrations{
    display: none;
}

li.full span.main_event_name, li.full span.event_date, li.full span.event_name{
    color: red !important;
}

li.inactive span.event_date, li.inactive span.main_event_name, li.inactive span.main_event_dates{
    color: gray !important;
    text-decoration: line-through;
}

li.new-link{
    margin: 5px 0px;
}

li.col_fajlok{
	clear: both;
}

li.main_event span.open-closer, span.main_event_name{
    font-size: 14px !important;
}

span.main_event_dates{
    font-weight: normal;
    margin: 0px 0px 0px 10px;
}

span.event_name{
    margin: 0px 10px 0px 0px;
}

span.open-closer, span.open-closer-all, span.open-closer-allout, span.open-closer-allin{
    margin-right: 10px;
    color: gray;
    cursor: pointer;
}

span.open-closer-space-holder{
    margin-right: 10px;
    color: white;
}

span.delete-link, span.edit-link{
    margin: 0px 0px 0px 20px;
}

span.view_link_container{
    margin: 0px 0px 0px 10px;
}

span.reg_email{
	width: 50px;
}

div#edit_event_dialog table tr td, div#new_event_dialog table tr td, div#edit_main_event_dialog table tr td, div#new_main_event_dialog{
    text-align: left;
}

div.error{
    margin: 10px;
    color: red;
    font-weight: bold;
    text-align: center;
}

div.picture_link_container{
    margin: 0px 0px 10px 0px;
}

a.view_link{
    color: #003C70 !important;
    font-size: 10px !important;
}

tr.neccessary td{
    font-weight: bold;
}

tr.neccessary td input{
    font-weight: normal !important;
    border: 1px solid black;
    background-color: #fdb910;
}

div.col_szint1, div.col_szint2, div.col_szint3{
	float: left;
}

div.col_szint1{
	width: 170px;
}

div.col_szint2{
	width: 150px;
}

div.col_szint3{
	width: 192px;
}

</style>
<?if($error):?>
<div class="error"><?=$error?></div>
<?endif;?>
<?if($tipusok):?>
<div id="confirm_dialog" style="display: none;" title="Törlés megerősítés"></div>
<div id="edit_event_dialog" style="display: none;" title="Kategória módosítása">
    <?=form_open('admin/kategedit', array('id' => 'modositas_form'))?>
    <input type="hidden" name="event_id" id="event_id" />
    <input type="hidden" name="event_main_id" id="event_main_id" />
    <input type="hidden" name="do" id="do" value="true" />
	<input type="hidden" name="dlid" id="dlid" value="" />
    <table cellspacing="0" cellpadding="10" border="0" align="center">
        <tr>
            <td>Típus:</td>
            <td>
            	<select name="tipus" id="tipus">
					<option value="door">door</option>
					<option value="group">group</option>
					<option value="lamp">lamp</option>
					<option value="object">object</option>
					<option value="project">project</option>
					<option value="window">window</option>
				</select>
            </td>
        </tr>
        <tr class="neccessary">
            <td>Magyar neve:</td>
            <td>
            	<input type=text name='nev_hun' id='nev_hun' value='' />
            </td>
        </tr>
        <tr class="neccessary">
            <td>Angol neve:</td>
            <td>
            	<input type=text name='nev_eng' id='nev_eng' value='' />
            </td>
        </tr>
    </table>
    <?=form_close()?>
</div>
<div id="edit_main_event_dialog" style="display: none;" title="Esemény módosítása">
    <?=form_open_multipart('admin/events_new', array('id' => 'modositas_main_form'))?>
    <?=form_hidden('do', 'modositas_main')?>
    <input type="hidden" name="event_main_id" id="event_main_id" />
    <input type="hidden" name="kep_eredeti" id="kep_eredeti" />
    <input type="hidden" name="thumb_eredeti" id="thumb_eredeti" />
    <table cellspacing="0" cellpadding="10" border="0" align="center">
        <tr class="neccessary">
            <td>Név:</td>
            <td><input type="text" name="nev" id="nev" size="60" /></td>
        </tr>
        <tr>
            <td valign="top">Leírás:<br /><i>(ez jelenik meg az oldal tetején)</i></td>
            <td><textarea name="leiras" rows="6" cols="40" id="leiras"></textarea></td>
        </tr>
        <tr>
            <td valign="top">Banner:<br /><i>(ez jelenik meg a rövid leírás alatt)</i></td>
            <td><input type="file" name="kep" id="kep" /></td>
        </tr>
        <tr>
            <td valign="top">Kis kép:<br /><i>(200x200 ez jelenik meg a rövid leírás mellett)</i></td>
            <td><input type="file" name="thumb" id="thumb" /></td>
        </tr>
        <tr>
            <td>Hivatalos weboldal:<br /><i>(ide ugrik a bannerre kattintva)</i></td>
            <td>
                <input type="text" name="weboldal" id="weboldal" size="30" />
                <span class="view_link_container"><a href="" target="_blank" class="view_link">megtekint</a></span>
            </td>
        </tr>
        <tr>
            <td>Részletező oldal:<br /><i>(ez jelenik meg a read more linkre kattintva)</i></td>
            <td valign="top">
                <select name="archline_oldal" id="archline_oldal">
                    <?foreach($event_pages as $page):?>
                    <option value="<?=$page->page_id?>"><?=$page->details->page_title?></option>
                    <?endforeach;?>
                </select>
                <span class="view_link_container"><a href="" target="_blank" class="view_link">megtekint</a></span>
            </td>
        </tr>
        <tr>
            <td>Sikeres regisztráció oldal:</td>
            <td>
                <select name="sikeres_reg_oldal" id="sikeres_reg_oldal">
                    <?foreach($event_pages as $page):?>
                    <option value="<?=$page->page_id?>"><?=$page->details->page_title?></option>
                    <?endforeach;?>
                </select>
                <span class="view_link_container"><a href="" target="_blank" class="view_link">megtekint</a></span>
            </td>
        </tr>
        <tr>
            <td>Sikeres regisztráció levél:</td>
            <td>
                <select name="sikeres_reg_mail" id="sikeres_reg_mail">
                    <?foreach($event_pages as $page):?>
                    <option value="<?=$page->page_id?>"><?=$page->details->page_title?></option>
                    <?endforeach;?>
                </select>
                <span class="view_link_container"><a href="" target="_blank" class="view_link">megtekint</a></span>
            </td>
        </tr>
        <tr>
            <td>Regisztráció törlés oldal:</td>
            <td>
                <select name="reg_torles_oldal" id="reg_torles_oldal">
                    <?foreach($event_pages as $page):?>
                    <option value="<?=$page->page_id?>"><?=$page->details->page_title?></option>
                    <?endforeach;?>
                </select>
                <span class="view_link_container"><a href="" target="_blank" class="view_link">megtekint</a></span>
            </td>
        </tr>
        <tr class="neccessary">
            <td>Főesemény kezdete:<br /><i>(ez nem időpont! új időpontot az esemény létrejötte után lehet felvenni)</i></td>
            <td valign="top"><input type="text" name="datum_kezdet" id="datum_kezdet" class="date" size="10" />&nbsp;-&nbsp;<input class="numeric" type="text" name="ora_kezdet" id="ora_kezdet" maxlength="2" size="2" />:<input class="numeric" type="text" maxlength="2" size="2" name="perc_kezdet" id="perc_kezdet" /></td>
        </tr>
        <tr class="neccessary">
            <td>Főesemény vége:</td>
            <td><input type="text" name="datum_veg" id="datum_veg" class="date" size="10" />&nbsp;-&nbsp;<input class="numeric" type="text" name="ora_veg" id="ora_veg" maxlength="2" size="2" />:<input class="numeric" type="text" maxlength="2" size="2" name="perc_veg" id="perc_veg" /></td>
        </tr>
        <tr>
            <td nowrap="nowrap">Létszám korlát*:</td>
            <td><input class="numeric" type="text" name="event_main_limit" id="event_main_limit" maxlength="3" size="3" /></td>
        </tr>
        <tr>
            <td>Alapértelmezett nézet:</td>
            <td>
                <select name="event_view_id" id="event_view_id">
                    <?foreach($event_views as $event_view):?>
                    <option value="<?=$event_view->event_view_id?>"><?=$event_view->name?></option>
                    <?endforeach;?>
                </select>
            </td>
        </tr>
        <tr>
            <td>Aktív:</td>
            <td><input type="checkbox" name="active" id="active" /></td>
        </tr>
        <tr>
            <td>RSS:</td>
            <td><input type="checkbox" name="rss" id="rss" /></td>
        </tr>
        <tr>
            <td colspan="2">*: 0 = nincs létszám korlát</td>
        </tr>
    </table>
    <?=form_close()?>
</div>
<div id="new_main_event_dialog" style="display: none;" title="Új esemény rögzítése">
    <?=form_open_multipart('admin/events_new', array('id' => 'rogzites_main_form'))?>
    <?=form_hidden('do', 'rogzites_main')?>
    <table cellspacing="0" cellpadding="10" border="0" align="center">
        <tr class="neccessary">
            <td>Név:</td>
            <td><input type="text" name="nev" id="nev_uj" size="60" /></td>
        </tr>
        <tr>
            <td valign="top">Leírás:<br /><i>(ez jelenik meg az oldal tetején)</i></td>
            <td><textarea name="leiras" rows="6" cols="40" id="leiras_uj"></textarea></td>
        </tr>
        <tr>
            <td valign="top">Banner:<br /><i>(ez jelenik meg a leírás alatt)</i></td>
            <td><input type="file" name="kep" id="kep_uj" /></td>
        </tr>
        <tr>
            <td valign="top">Kis kép:<br /><i>(200x200 ez jelenik meg a rövid leírás mellett)</i></td>
            <td><input type="file" name="thumb" id="thumb_uj" /></td>
        </tr>
        <tr>
            <td>Hivatalos weboldal:<br /><i>(ide ugrik a bannerre kattintva)</i></td>
            <td>
                <input type="text" name="weboldal" id="weboldal_uj" size="30" />
                <span class="view_link_container"><a href="" target="_blank" class="view_link">megtekint</a></span>
            </td>
        </tr>
        <tr>
            <td>Részletező oldal:<br /><i>(ez jelenik meg a read more linkre kattintva)</i></td>
            <td valign="top">
                <select name="archline_oldal" id="archline_oldal_uj">
                    <?foreach($event_pages as $page):?>
                    <option value="<?=$page->page_id?>"><?=$page->details->page_title?></option>
                    <?endforeach;?>
                </select>
                <span class="view_link_container"><a href="" target="_blank" class="view_link">megtekint</a></span>
            </td>
        </tr>
        <tr>
            <td>Sikeres regisztráció oldal:</td>
            <td>
                <select name="sikeres_reg_oldal" id="sikeres_reg_oldal_uj">
                    <?foreach($event_pages as $page):?>
                    <option value="<?=$page->page_id?>"><?=$page->details->page_title?></option>
                    <?endforeach;?>
                </select>
                <span class="view_link_container"><a href="" target="_blank" class="view_link">megtekint</a></span>
            </td>
        </tr>
        <tr>
            <td>Sikeres regisztráció levél:</td>
            <td>
                <select name="sikeres_reg_mail" id="sikeres_reg_mail_uj">
                    <?foreach($event_pages as $page):?>
                    <option value="<?=$page->page_id?>"><?=$page->details->page_title?></option>
                    <?endforeach;?>
                </select>
                <span class="view_link_container"><a href="" target="_blank" class="view_link">megtekint</a></span>
            </td>
        </tr>
        <tr>
            <td>Regisztráció törlés oldal:</td>
            <td>
                <select name="reg_torles_oldal" id="reg_torles_oldal_uj">
                    <?foreach($event_pages as $page):?>
                    <option value="<?=$page->page_id?>"><?=$page->details->page_title?></option>
                    <?endforeach;?>
                </select>
                <span class="view_link_container"><a href="" target="_blank" class="view_link">megtekint</a></span>
            </td>
        </tr>
        <tr class="neccessary">
            <td>Főesemény kezdete:<br /><i>(ez nem időpont! új időpontot az esemény létrejötte után lehet felvenni)</i></td>
            <td valign="top"><input type="text" name="datum_kezdet" id="datum_kezdet_uj" size="10" />&nbsp;-&nbsp;<input class="numeric" type="text" name="ora_kezdet" id="ora_kezdet_uj" maxlength="2" size="2" />:<input class="numeric" type="text" maxlength="2" size="2" name="perc_kezdet" id="perc_kezdet_uj" /></td>
        </tr>
        <tr class="neccessary">
            <td>Főesemény vége:</td>
            <td><input type="text" name="datum_veg" id="datum_veg_uj" size="10" />&nbsp;-&nbsp;<input class="numeric" type="text" name="ora_veg" id="ora_veg_uj" maxlength="2" size="2" />:<input class="numeric" type="text" maxlength="2" size="2" name="perc_veg" id="perc_veg_uj" /></td>
        </tr>
        <tr>
            <td nowrap="nowrap">Létszám korlát*:</td>
            <td><input class="numeric" type="text" name="event_main_limit" id="event_main_limit_uj" maxlength="3" size="3" value="0" /></td>
        </tr>
        <tr>
            <td>Alapértelmezett nézet:</td>
            <td>
                <select name="event_view_id" id="event_view_id_uj">
                    <?foreach($event_views as $event_view):?>
                    <option value="<?=$event_view->event_view_id?>"><?=$event_view->name?></option>
                    <?endforeach;?>
                </select>
            </td>
        </tr>
        <tr>
            <td>Aktív:</td>
            <td><input type="checkbox" name="active" id="active_uj" checked="checked" /></td>
        </tr>
        <tr>
            <td>RSS:</td>
            <td><input type="checkbox" name="rss" id="rss" /></td>
        </tr>
        <tr>
            <td colspan="2">*: 0 = nincs létszám korlát</td>
        </tr>
    </table>
    <?=form_close()?>
</div>
<div id="new_event_dialog" style="display: none;" title="Új időpont rögzítése">
    <?=form_open('admin/events_new', array('id' => 'rogzites_form'))?>
    <?=form_hidden('do', 'rogzites')?>
    <input type="hidden" name="event_main_id" id="event_main_id_uj" />
    <table cellspacing="0" cellpadding="10" border="0" align="center">
        <tr class="neccessary">
            <td>Név:</td>
            <td><input type="text" name="nev" id="nev_uj" /></td>
        </tr>
        <tr class="neccessary">
            <td>Dátum:</td>
            <td><input type="text" name="datum" id="datum_uj" /></td>
        </tr>
        <tr class="neccessary">
            <td>Kezdete:</td>
            <td><input class="numeric" type="text" name="ora_kezdet" id="ora_kezdet_uj" maxlength="2" size="2" />:<input class="numeric" type="text" maxlength="2" size="2" name="perc_kezdet" id="perc_kezdet_uj" /></td>
        </tr>
        <tr class="neccessary">
            <td>Vége:</td>
            <td><input class="numeric" type="text" name="ora_veg" id="ora_veg_uj" maxlength="2" size="2" />:<input class="numeric" type="text" maxlength="2" size="2" name="perc_veg" id="perc_veg_uj" /></td>
        </tr>
        <tr>
            <td nowrap="nowrap">Létszám korlát:</td>
            <td><input class="numeric" type="text" name="event_limit" id="event_limit_uj" maxlength="3" size="3" /></td>
        </tr>
        <tr>
            <td>Aktív:</td>
            <td><input type="checkbox" name="active" id="active_uj" checked="checked" /></td>
        </tr>
    </table>
    <?=form_close()?>
</div>

<a href="/admin/collection2" style="margin-left: 10px;"><b>Új collection elemeinek szerkesztése</b></a>

<p align="right">
	Mindet
	<span class="open-closer-allin">kinyit</span> / <span class="open-closer-allout">bezár</span>
</p>
<ul class="main_events">
    <?foreach($tipusok as $tipus):?>
    <li class="main_event" event_main_id="<?=$tipus->tipus?>">
        <div class="col_szint1">
        <span class="open-closer">+</span>
        <span class="main_event_name"><?=$tipus->tipus?></span>
        <span class="main_event_dates">(<?=$tipus->darab?>)</span>
        </div>
        <span class="edit-link"></span>
        <span class="view-link">
            <?=anchor('http://www.archline.hu/collection/kategoria/'.$tipus->kategoria[0]->dl_id, ' Megtekintés', 'target="_blank"')?>
        </span>
        <span class="delete-link"></span>
    </li>
        <ul class="events">
            <?if($tipus->kategoria):?>
            <li class="new-link" event_main_id="<?=$tipus->kategoria?>"><?=anchor('/admin/kategedit/new/'.$tipus->tipus, 'új kategória rögzítése', 'class="new_anchor"')?></li>
            <?foreach($tipus->kategoria as $kategoria):?>
            <li class="event" event_name="<?=$kategoria->nev?>" event_name_eng="<?=$kategoria->nev_eng?>" dl_id="<?=$kategoria->dl_id?>" event_main_id="<?=$kategoria->dl_id?>" event_start_hour="<?=date('H', time())?>" tipus="<?=$tipus->tipus?>" event_limit="<?=$kategoria->dl_id?>">
                <div class="col_szint2">
                <?if($kategoria->fajl):?>
                <span class="open-closer">+</span>
                <?else:?>
                <span class="open-closer-space-holder">+</span>
                <?endif;?>
                <span class="event_name"><?=$kategoria->nev?></span>
                <span class="event_date">(<?=$kategoria->darab?>)</span>
                </div>
                <span class="edit-link">
					<?=anchor('http://www.archline.hu/collection/kategoria/'.$kategoria->dl_id, ' Megtekintés', 'target="_blank"')?>
				</span>
                <span class="edit-link"><?=anchor('/admin/kategedit/'.$kategoria->dl_id, 'módosítás', 'class="edit_anchor" event_id="'.$kategoria->dl_id.'"')?>
                </span>
                <span class="delete-link"><?=anchor('/admin/delkateg/'.$kategoria->dl_id, 'törlés', 'class="del_anchor" question="Biztosan törli a kategóriát?"')?></span>
            </li>
            <?if($kategoria->fajl):?>
            <ul class="registrations">
                <?foreach($kategoria->fajl as $fajl):?>
                <li class="col_fajlok">
                    <div class="col_szint3">
                    <span class="reg_email"><?=$fajl->title?></span>
                    </div>
                    <span class="edit-link"><?=anchor('/admin/groupsedit/'.$fajl->c_id, 'módosítás', 'class="edit_anchor888" event_id="'.$fajl->c_id.'"')?></span>
                    <span class="delete-link"><?=anchor('admin/delgroup/'.$fajl->c_id, 'törlés', 'class="del_anchor" question="Biztosan törli a regisztrációt?"')?></span>
                </li>
                <?endforeach;?>
            </ul>
            <?endif;?>
            <?endforeach;?>
            <li class="new-link" event_main_id="<?=$main_event->event_main_id?>"></li>
            <?else:?>
            <li class="new-link" event_main_id="<?=$main_event->event_main_id?>"><?=anchor('', 'új időpont rögzítése', 'class="new_anchor"')?></li>
            <?endif;?>
        </ul>
    <?endforeach;?>
</ul>
<?else:?>
<p>No events!</p>
<?endif;?>