<?php
$table = $usection; // for sorting function
?>
<script type="text/javascript">
jQuery(function($){
	$('a[rel="open_events"]').fancybox({
		onClosed			: function() {},
		'overlayOpacity'		: 0.9,
		'overlayColor'		:'#000',
		'width'			: 750,
		'height'			: 600,
		'autoScale'			: false,
		'type'				: 'iframe',
		'showNavArrows'		: false,
		'titleShow'			: false
	});
	$('a[rel="open_gmap"]').fancybox({
		onClosed			: function() {},
		'overlayOpacity'		: 0.9,
		'overlayColor'		:'#000',
		'width'			: 600,
		'height'			: 600,
		'autoScale'			: false,
		'type'				: 'iframe',
		'showNavArrows'		: false,
		'titleShow'			: false
	});		
	
	function format(state) {
		if (!state.text) return false;
		return state.text;
	}				
	

	<?php
	$option = ($_REQUEST['option']) ? $_REQUEST['option'] : null;
	$option = (empty($option) && $itemID && $_POST['submitedData']) ? "option2" : $option;
	$option = (empty($option)) ? "option1" : $option;
	if($itemID && $option && $hasAttachments && $action=="form"){
	?>
	setSelected(document.getElementById('<?php echo $option;?>'));	
	<?php
	}
	?>
		
});

<?php 
global $useTags;
global $useCalendar;
function getCountyName($cityID){
	global $db;
	global $langID;
	$queryLangID = ($langID != 1) ? 2 : $langID;
	$q = "select content_counties.title as name 
							from counties, content_counties, cities 
							where cities.countyID=counties.id and 
							content_counties.mainID=counties.id and 
							cities.id='$cityID' and content_counties.langID='$queryLangID'";
	$countyRow = $db->getRecord($q);
	return $countyRow->name;
}
if($_REQUEST['action']=="form"){

$regional = ($language->getLanguageExtension($langID) == "_gr") ? "el" : "en";
?>
tinyMCE.init({
// General options
apply_source_formatting : true,

mode : "specific_textareas",
formats : {
	col : {block : 'div', classes : 'col', wrapper : 1}
},
editor_selector : "mceEditor",
theme : "advanced",
entity_encoding : "raw",
convert_urls: false,
language : "<?php echo $regional;?>",
plugins : "safari,style,table,inlinepopups,preview,paste,advlink,fullscreen,media,advimage",
    setup : function(ed) {
        // Add a custom button
        ed.addButton('cols', {
            title : 'Cols Layout',
            image : 'images/cols.gif',
            onclick : function() {
                // Add you own code to execute something on click
                ed.focus();
		ed.formatter.toggle('col');

            }
        });
    },

// Theme options
theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright, |, link,unlink,code",
theme_advanced_buttons2 : "bullist,numlist,|,hr,|,fullscreen,preview,charmap,|,media,image,sub,sup",
theme_advanced_buttons3 : "<?php  if($parameters->getParameter('editor') == "1"){?>,styleprops,forecolor,backcolor,<?php 
} ?>",
theme_advanced_buttons4 : "<?php  if($parameters->getParameter('editor') == "1"){?>tablecontrols<?php } ?>",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true,
content_css : "<?php  echo getBase();?>admin/css/editor.css?r="+ new Date().getTime()
});



jQuery(function($){
	<?php if($regional == "el"){ ?>
	$.datepicker.regional['lang'] = {
		closeText: 'Κλείσιμο',
		prevText: 'Προηγούμενος',
		nextText: 'Επόμενος',
		currentText: 'Τρέχων Μήνας',
		monthNames: ['Ιανουάριος','Φεβρουάριος','Μάρτιος','Απρίλιος','Μάιος','Ιούνιος',
		'Ιούλιος','Αύγουστος','Σεπτέμβριος','Οκτώβριος','Νοέμβριος','Δεκέμβριος'],
		monthNamesShort: ['Ιαν','Φεβ','Μαρ','Απρ','Μαι','Ιουν',
		'Ιουλ','Αυγ','Σεπ','Οκτ','Νοε','Δεκ'],
		dayNames: ['Κυριακή','Δευτέρα','Τρίτη','Τετάρτη','Πέμπτη','Παρασκευή','Σάββατο'],
		dayNamesShort: ['Κυρ','Δευ','Τρι','Τετ','Πεμ','Παρ','Σαβ'],
		dayNamesMin: ['Κυ','Δε','Τρ','Τε','Πε','Πα','Σα'],
		weekHeader: 'Εβδ',
		dateFormat: 'dd/mm/yy',
		firstDay: 1,
		isRTL: false,
		showMonthAfterYear: false,
		yearSuffix: ''};
	<?php
	 }else{
	?>
	$.datepicker.regional['lang'] = {
		dateFormat: 'dd/mm/yy'
	}
	<?php	 
	 }
	 ?>
 	$.datepicker.setDefaults($.datepicker.regional['lang']);
	$('#ui-datepicker-div').css("display", "none");
	$('#dialog_link, ul#icons li').hover(
	function() { $(this).addClass('ui-state-hover'); }, 
	function() { $(this).removeClass('ui-state-hover'); }
	);	
});


function MM_validateForm() { //v4.0
	if(document.getElementById('delete')){
		if(document.getElementById('delete').checked) return true;
	}
	var desc = new Array;
	<?php 
	
	if($requiredVars){
		$validationJS = 'onClick="MM_validateForm(';
		foreach($requiredVars as $row){
			$varName = ($row->isMultilingual)? $row->fieldVarName.$language->getLanguageExtension($defaultLanguage) : $row->fieldVarName;
			echo "desc['$varName']='".t($row->fieldDescription)."';
			";
			$validationJS.= "'".$varName."','','R',";
		}
		$validationJS = substr($validationJS ,0 ,-1);
		$validationJS.= ');return document.MM_returnValue"';
	}
	?>
	if (document.getElementById){
		var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
		for (i=0; i<(args.length-2); i+=3) {
			test=args[i+2]; val=document.getElementById(args[i]); 
			if (val) {
				nm=val.name;
				if (val.value=="" && test.charAt(0) == 'R') errors += '• <?php echo t("Το πεδίο");?> «'+desc[nm]+'» <?php echo t("πρέπει να συμπληρωθεί");?>\n';  
			}
		}
		if (errors) alert('<?php echo t("Βρέθηκαν τα ακόλουθα σφάλματα");?>:\n\n'+errors);
		document.MM_returnValue = (errors == '');
	} 
}
<?php 
}
?>


function toggleSearch(btn){
	btn = $(btn);
	var elm = $('#find');
	if(btn.hasClass("search_off")){
		btn.removeClass("search_off");
		btn.addClass("search_on");
		elm.removeClass("hidden");
		elm.addClass("visible");
		$('#keyword').focus();		
	}else{
		btn.removeClass("search_on");
		btn.addClass("search_off");
		elm.removeClass("visible");
		elm.addClass("hidden");			
	}
}

function CheckLabel(obj){
	var f = document.getElementById('edit_delete');
	if (obj.checked){
		f.value="<?php echo t("Διαγραφή");?>";
		f.className="btn btn-danger";
	}else{
		f.value="<?php echo t("Αποθήκευση");?>";
		f.className="btn btn-success";
	}
}

function checkMassDelete(){
	var objCheckBoxes = document.getElementById('massSelectionForm').elements["delID[]"];
	var countCheckBoxes = objCheckBoxes.length;
		if(countCheckBoxes){
	for(var i = 0; i < countCheckBoxes; i++){
		var obj = objCheckBoxes[i];
		if(obj.checked) {
			return confirm("<?php echo t("Θέλετε να διαγραφούν οριστικά οι επιλεγμένες εγγραφές;");?>");
		}
	}
	}else{
		var obj = objCheckBoxes;
		if(obj.checked) {
			return confirm("<?php echo t("Θέλετε να διαγραφεί οριστικά η επιλεγμένη εγγραφή;");?>");
		}
	}
	alert("<?php echo t("Δεν έχετε επιλέξει καμία εγγραφή!");?>");
	return false;
}

function checkMassSelection(){
	if($('#withSelected').val() == "deactivate"){
		text1 = "<?php echo t("απενεργοποιηθούν");?>";
		text2 = "<?php echo t("απενεργοποιηθεί");?>";
	}
	var objCheckBoxes = document.getElementById('massSelectionForm').elements["delID[]"];
	var countCheckBoxes = objCheckBoxes.length;
		if(countCheckBoxes){
	for(var i = 0; i < countCheckBoxes; i++){
		var obj = objCheckBoxes[i];
		if(obj.checked) {
			return confirm("<?php echo t("Θέλετε να");?> "+text1+" <?php echo t("οι επιλεγμένες εγγραφές;");?>");
		}
	}
	}else{
		var obj = objCheckBoxes;
		if(obj.checked) {
			return confirm("<?php echo t("Θέλετε να");?> "+text2+" <?php echo t("η επιλεγμένη εγγραφή;");?>");
		}
	}
	alert("<?php echo t("Δεν έχετε επιλέξει κάποια εγγραφή!");?>");
	return false;
}

function checkMassActivation(){
	var objCheckBoxes = document.getElementById('massSelectionForm').elements["delID[]"];
	var countCheckBoxes = objCheckBoxes.length;
		if(countCheckBoxes){
	for(var i = 0; i < countCheckBoxes; i++){
		var obj = objCheckBoxes[i];
		if(obj.checked) {
			return true
		}
	}
	}else{
		var obj = objCheckBoxes;
		if(obj.checked) {
			return true;
		}
	}
	alert("<?php echo t("Δεν έχετε επιλέξει κάποια εγγραφή!");?>");
	$('#withSelected').val("");
	return false;
}

function format(state) {
	if (!state.text) return false;
	return state.text;
}

function selectAllOptions(id){
	var elm = document.getElementById(id);
	for(i=0;i<elm.options.length;i++){
		elm.options[i].selected=true;
	}
	$('#'+id).select2({
		formatResult: format,
		formatSelection: format,
		width: 'element'
	});
	document.getElementById('forceDeleteOptions').value='0';
}
function diselectAllOptions(id){
	document.getElementById(id).selectedIndex = -1;
	$('#'+id).select2({
		formatResult: format,
		formatSelection: format,
		width: 'element'
	});	
	document.getElementById('forceDeleteOptions').value='1';
}

function selectAllcb(elm){
	var elm = $(elm);
	setTimeout(function(){
		$('[name^=delID], [name^=selectedID]').each(function(){
			if($(this).is(":visible") == true) $(this).prop("checked", elm.prop("checked"));
		});
	}, 50);
}

<?php 
if($_REQUEST['action'] == "sort"){
?>

$(document).ready(function() {
	$("#sort-list").sortable({
		handle : '.handle',
		update : function () {
			var order = $('#sort-list').sortable('serialize');
			$("#sortInfo").load("admin/sort.php?"+order+"&table=<?php echo $table; ?>");
		}
	});
});

function setDragStyle(elm, typeOfEvent){
	if(typeOfEvent == "startDrag"){
		$(elm).parent().addClass("sort_hover");
		$(elm).parent().find('.sort_title').css("color", "white"); 
	}else{
		$(elm).parent().removeClass("sort_hover");
		$(elm).parent().find('.sort_title').css("color", "#<?php echo $colorSecondaryDark;?>");
	}
}

<?php 
}

//if($itemID && $hasAttachments && $action=="form"){
?>
function setSelected(elm){
	window.option = elm.id;
	var id = elm.id+"content";
	$('#option1').removeClass("edit_bar_selected");
	$('#option2').removeClass("edit_bar_selected");
	$('#option3').removeClass("edit_bar_selected");
	$(elm).addClass("edit_bar_selected");
	$('#option1content').hide();
	$('#option2content').hide();
	$('#option3content').hide();
	$('#'+id).show();
}
<?php
//}
?>


//-->
</script>