/**
 * base-web.js
 * Author: Jerry Smith
 * Code base: ExtJS library
 * NOTE: Include this javascript file after the EXTJS libraries, and before
 * the other base-web files.
 * This file contains the objects that are global to the website.
 * Do not place page-specific code in this file.
 */
 Ext.namespace('web.base');
 Ext.namespace('web.base.data');
 Ext.QuickTips.init(); // needed for closing tabs (bug fixed in ExtJS 3).
 
 var DEFAULT_DATASTORE_ERRORMSG = "We're sorry, but your request cannot be completed due to technical difficulties at this time.  Please refresh the page and try again.";
 
 /**
  * The left-hand site navigation.  This is a panel using an accordion layout.
  * xtype: 'baseSiteNavigation'
  */
 web.base.sitenavigation = Ext.extend(Ext.Panel, {
 	initComponent: function(){
 		Ext.apply(this, {
			split: true,
			width: 200,
			title: 'Navigation',
			layout: 'accordion'
 		});
 		
 		web.base.sitenavigation.superclass.initComponent.call(this);
 	}
 });
 Ext.reg('baseSiteNavigation', web.base.sitenavigation);
 
 web.base.data.Store = function(config){
 	var tmpStore = new Ext.data.Store(config);
 	var errorMessage;
 	
	if(config.errorMessage === undefined || config.errorMessage === null){
		errorMessage = DEFAULT_DATASTORE_ERRORMSG;
	}
	else{
		errorMessage = config.errorMessage;
	}
	
	tmpStore.on({
		'loadexception':function(){
			// alert the user that an error has occurred:
			Ext.Msg.alert("Technical Difficulty", errorMessage);
		}
	});

	return tmpStore;
 	// web.base.data.Store.superclass.constructor.call(this, config);
 }
Ext.reg('baseDataStore', web.base.data.Store); 

 /**
  * Attempts to open a new window.  If a new window cannot be opened then a 
  * message is displayed to the user informing them to make sure all popup blockers
  * are turned off.  If you would like to provide a custom message, then pass it
  * in as a second parameter to link.
  */
 web.base.openWindow = function(link){
	if(!window.open(link))
	{
		// notify the user that they should turn popup blockers off for this operation:
		Ext.Msg.alert('Open Window', (arguments.length > 1) ? arguments[1] : 'Unable to create new window.  Please make sure all popup blockers are turned off and try again.');
	}
 }
 
 
 