/*
	Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
	Available via Academic Free License >= 2.1 OR the modified BSD license.
	see: http://dojotoolkit.org/license for details
*/


dojo.require('com.frazerbilt.layer');

// add iOS classes to HTML tag if the user is on an iPhone or an iPad
var isiPad = navigator.userAgent.match(/iPad/i) != null;
var isiPhone = navigator.userAgent.match(/iPhone/i) != null;
if (isiPad == true || isiPhone == true) {
  var isIOS = true;
  dojo.addClass(dojo.query("html")[0], "dj_iOS");
}

var base = {
  
  newWindow: function(url) {
    window.open(url, "");
  },
  
  /**
   * This method should be used to check if the browser supports "most" CSS 3 and HTML 5.
   * 
   * If the browser does not meet these requirements...
   * 
   * Internet Explorer 8.0 and below
   * below Fire Fox 4.0
   * below Chrome 5.0
   * below Opera 10.0
   * 
   * Then the method returns false.
   * 
   * Otherwise, it will return true.
   * 
   */
  isModernBrowser: function() {
    
    /* 
     * Browsers NOT supported. If these browsers are encountered, the user will
     * be redirected to the browsers support page.
     * 
     * IE 6
     * FF 2
     * Safari 3
     * Chrome 3
     * Opera 9
    */
    
    if (dojo.isIE < 7 || dojo.isFF < 3 || dojo.isSafari < 4 || dojo.isChrome < 4 || dojo.isOpera < 10) {
      browserNotSupported();
      return false;
      
    } else {
      
      // Browser is supported.
      
      if (dojo.isIE <= 8 || dojo.isFF < 4) {
        // Browser IS supported, but still does not support CSS3/HTML5
        return false;
      } else {
        // Browser supports CSS3/HTML5 and is considered a modern browser.
        return true;
      }
    }
  },
  
  browserNotSupported: function() {
    dojo.style(dojo.body(), "display", "none");
    base.getUrl("/Support/browsers.php");
  },

  months: {
    1:"Jan",
    2:"Feb",
    3:"Mar",
    4:"Apr",
    5:"May",
    6:"Jun",
    7:"Jul",
    8:"Aug",
    9:"Sep",
    10:"Oct",
    11:"Nov",
    12:"Dec"
  },
  
  getUrl: function(value) {
    window.location.href = value;
  },
  
  formatDate: function(value) {
    var date = value.split(" ")[0];
    var month = base.months[Number(date.split("-")[1])];
    var day = date.split("-")[2];
    var year = date.split("-")[0];
    var datetime = month + " " + day + ", " + year;
    return datetime;
  },
  
  formatSmallDate: function(value) {
    
    var date = value.split(" ")[0];
    
    var month = Number(date.split("-")[1]);
    
    var day = date.split("-")[2];
    
    var year = date.split("-")[0];
    
    year = year.substr(2)
    
    var datetime = month + "/" + day + "/" + year;
    
    return datetime;
    
  }
};

