﻿
var SCIwatch = $.extend( SCIwatch, {
  User: {
    Username: "unknown",
    Role: "unknown",
    CurrencySymbol: "$",
    DateFormat: "M/d/yy h:mmtt",
    Metric: false
  },

  createReports: function ( opts ) {
    return opts.$dest.sciReports( opts );
  },

  createChart: function ( opts ) {
    return opts.$dest.sciChart( opts );
  },

  createGrid: function ( opts ) {
    return opts.$dest.sciGrid( opts );
  },

  createAssetFinder: function ( opts ) {
    opts.$dest = $( ".scoper .header" );
    return opts.$dest.sciAssetFinder( opts );
  },

  createDatePicker: function ( opts ) {
    opts.$dest = $( ".scoper .header" );
    return opts.$dest.sciDatePicker( opts );
  },

  createPropertiesEditor: function ( opts ) {
    return opts.$widget.sciPropertiesEditor( opts );
  },

  ClearUserData: function() {
    $.cookie( "dp", null );
    $.cookie( "af", null );
  },

  template: function( template, values ) {
    return $.ui.scicon.prototype.template( template, values );
  },

  checkCapsLock: function( $el, callback ) {
    $el.keypress(function( e ) { 
      var s = String.fromCharCode( e.which );
      if ( s.toUpperCase() === s && s.toLowerCase() !== s && !e.shiftKey ) {
        callback( true );
      }
      else {
        callback( false );
      }
    });
  },

  redirectOnIsAuth: function( isAuth ) {
    var c = $.cookie( "AUTH" ); 

    var loc = "";
    if( isAuth && c ) {
      loc = "/";
    }
    else if( !c && window.location.toString().indexOf( "/Account/LogOn" ) == -1 ) {
      loc = "/Account/LogOn?ReturnUrl=" + window.location.href;
    }

    if( loc ) { 
      window.location = loc;
    }
  }
} );

