SetSaveColUrl2(); // xadm.js must already have been loaded

function SetSaveColUrl2()
{
   var ar1=location.href.split('/');
   if (ar1.length<=0)
      return;
      
   ar1.pop();
   ar1.push('esend_visual.php');
   SavePageColsUrl=ar1.join('/');             
}

function goGgde()
{
   $("<a>").attr("href", 'http://www.publicrevenue.gr').attr("target", "ggde")[0].click();
}

function goMinfin()
{
   $("<a>").attr("href", "http://www.minfin.gr").attr("target", "minfin")[0].click();
}

function allUsers(fx)          
{
   var g=document.goForm;
	if (g==null) {
      g=document.createElement('FORM');
      g.name='goForm';
      document.body.appendChild(g);
   }
   
   var o2=g.ALLUSERS;
   if (o2==undefined) {
      o2=document.createElement('INPUT');
      o2.type='hidden';
      o2.name='ALLUSERS';
      g.appendChild(o2);
   }
   o2.value = $('#allusr').is(":checked")?1:0;
   
   goTo(fx);
}

function goDelEafdss(eafdss)
{
   location.href = location.pathname+'?FUNCTION=103&EAFDSS='+eafdss;
}

function create_vat_widget()
{
    $.widget( "ui.combobox", {
      _create: function() {
        var input,
          that = this,
          wasOpen = false,
          select = this.element.hide(),
          selected = select.children( ":selected" ),
          value = selected.val() ? selected.text() : "",
          wrapper = this.wrapper = $( "<span>" )
            .addClass( "ui-combobox" )
            .insertAfter( select );
 
        function processValue( element ) {
          var value=$( element ).val(), 
            valid = value.length==9 && value.match(/^\d+$/);
 
          if ( !valid ) {
            $( element )
              .attr( "title", "VAT no. should be 9 digits." )
              .tooltip( "open" );
            select.val( "" );
            setTimeout(function() {
              input.tooltip( "close" ).attr( "title", "" );
            }, 2500 );
            input.data( "ui-autocomplete" ).term = "";
          }
          else {
            document.goForm.VATNO.value = value;
          }                               
        }
 
        input = $( "<input>" )
          .appendTo( wrapper )
          .val( value )
          .attr( "title", "" )
          .addClass( "ui-state-default ui-combobox-input" )
          .autocomplete({
            delay: 0,
            minLength: 0,
            source: function( request, response ) {
              var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
              response( select.children( "option" ).map(function() {
                var text = $( this ).text();
                if ( this.value && ( !request.term || matcher.test(text) ) )
                  return {
                    label: text.replace(
                      new RegExp(
                        "(?![^&;]+;)(?!<[^<>]*)(" +
                        $.ui.autocomplete.escapeRegex(request.term) +
                        ")(?![^<>]*>)(?![^&;]+;)", "gi"
                      ), "<strong>$1</strong>" ),
                    value: text,
                    option: this
                  };
              }) );
            },
            select: function( event, ui ) {
              ui.item.option.selected = true;
              that._trigger( "selected", event, {
                item: ui.item.option
              });
            },
            change: function( event, ui ) {
              if ( !ui.item ) {
                processValue( this );
              }
            }
          })
          .addClass( "ui-widget ui-widget-content ui-corner-left" );
 
        input.data( "ui-autocomplete" )._renderItem = function( ul, item ) {
          return $( "<li>" )
            .append( "<a>" + item.label + "</a>" )
            .appendTo( ul );
        };
 
        $( "<a>" )
          .attr( "tabIndex", -1 )
          .attr( "title", "Show All Items" )
          .tooltip()
          .appendTo( wrapper )
          .button({
            icons: {
              primary: "ui-icon-triangle-1-s"
            },
            text: false
          })
          .removeClass( "ui-corner-all" )
          .addClass( "ui-corner-right ui-combobox-toggle" )
          .mousedown(function() {
            wasOpen = input.autocomplete( "widget" ).is( ":visible" );
          })
          .click(function() {
            input.focus();
 
            // close if already visible
            if ( wasOpen ) {
              return;
            }
 
            // pass empty string as value to search for, displaying all results
            input.autocomplete( "search", "" );
          });
 
        input.tooltip({
          tooltipClass: "ui-state-highlight"
        });
      },
 
      _destroy: function() {
        this.wrapper.remove();
        this.element.show();
      }
    });
}

function goAddEafdss()
{
   document.goForm.VATNO.value = $('.ui-combobox').find('input').val();
   document.goForm.submit();
}

function resetImg()
{
   $('#veryImg').attr('src', $('#veryImg').attr('src') );
}

var pageloaded = new Date();

$(function(){
   $('.bigButton').
      mouseenter(function(){ $(this).css('background-color','#23A7B6'); } ).
      mouseleave(function(){ $(this).css('background-color','#D6E8ED'); } );
      
   $(document).on('click keydown', function(){
      pageloaded = new Date();
   });
} )
