//EF Script
function __EFInitialize()
{
    jQuery(document).ready(function(){ 
        if (EFIsTooltipEnabled())
            jQuery('[jtip]').tooltip(); 

        jQuery('div.contextMenu').hide();
        
        EFProcessViewFormElements();
        
        jQuery('tr.GridNormal, td.GridNormal, tr.GridAlternate, td.GridAlternate').mouseover(function(){ 
            jQuery(this).addClass('GridHighlight');
        }).mouseout(function(){ 
            jQuery(this).removeClass('GridHighlight');
        });        
        
        //masking
        //jQuery('input[fieldtype="date"]').mask("99/99/9999");
        
        //date picker
        var dateformat = 'dd/mm/yy';
        var decimalformat = ".";
        if(isDefined('dnn'))
        {
            dateformat = dnn.getVar('ETHDateFormat');
            decimalformat = dnn.getVar('ETHDecimalFormat');
        }
        if (dateformat == null)
        {
            //EFLogConsole('Date format: using default');
            dateformat = 'dd/mm/yy';
        }
        if (decimalformat == null)
        {
            decimalformat = ".";
        }
                        
        //EFLogConsole('Date format: ' + dateformat);
        
        
        jQuery('input[fieldtype="date"]').datepicker({
            dateFormat: dateformat,
            changeMonth: true,
            changeYear: true,
            showButtonPanel: true
        });
        
        
        //decimal fields
        jQuery('input[fieldtype="decimal"]').format({type:'decimal',decimal:decimalformat});

    });
}


function EFProcessViewFormElements()
{
    if (EFIsViewFormPage())
    {
        jQuery("input[efpostback][type='image'], a[efpostback]").bind("click", function(){
            
            //alert('clicked');
            if (__EFDisableBtn(this.id))
            {
                var id = this.id;
                id = id.replace(/_/g, '$');            
                
                __doPostBack(id,'');
                                
                return false;
            }
            else
            {
                return false;
            }
        });

        jQuery("input[efevent][type='text'], select[efevent], textarea[efevent]").each(function(){
            var id = this.id;
            
            jQuery(this).bind("change", function(){
                __EFDisableBtn(id);
                return false;
            });
        });

        jQuery("span[efevent] > input, table[efevent] > input").each(function(){
            var id = this.id;
            
            jQuery(this).bind("change", function(){
                __EFDisableBtn(id);
                __doPostBack(id.replace(/_/g, '$'),'');
                return false;
            });
        });

        jQuery("table[efevent] input").each(function(){
            var id = this.id;
            
            jQuery(this).bind("change", function(){
                __EFDisableBtn(id);
                //__doPostBack(id.replace(/_/g, '$'),'');
                return false;
            });
        });
        
        jQuery("input[efpostback][type='text'][onkeypress]").each(function(){
            var id = this.id;
            
            //jQuery(this).unbind("keypress");
            jQuery(this).bind("change", function(){
                __EFDisableBtn(id);
                return false;
            });
        });

    }
}