/**
##############################################################################################
#
#		Title: Common
#
#		Description: Behaviour common to all RaW pages
#
##############################################################################################
#   $Id: common.js 536 2009-02-02 14:32:51Z Dave $ 
##############################################################################################
*/
Common = {
	
	/**
	 * Properties
	 */
	emptySearchMessage: "You didn't enter a search term, please enter some keywords in the search box.",
	flashVersion: 9, // Flash version to require when performing plugin detection
	sessionPath: null, // Path to use for session cookie for this page
	sessionName: null, // Name to use for session cookie for this page
	helpListeners: [], // Listeners added to 'h' key
		
	retryTimeout: 1000, // Time in ms to retry initialising if page is not yet rendered. 
	retryAttempts: 2, // Number of times to retry initialisation
	
	/**
	 * Function: init
	 * 
	 * Description: Performs onLoad initialisation of behaviour
	 */
	init : function(){			
		//This is a workaround for an IE race condition where Common.init is sometimes executed before the DOM has finished loading	
		if (!$('blq-foot')){
			if (Common.retryAttempts > 0){
				Common.retryAttempts--;
				window.setTimeout("Common.init()", Common.retryTimeout);					
			}
			return;
		}
		
		if ($('search-form')) {			
			bbcjs.dom.addEventListener($('search-form'), 'submit', Common.onSubmitSearch);
		}
		
		if ($('btm-printpreview')) {
			bbcjs.dom.addEventListener($('btm-printpreview'), 'click', Common.onClickPrintPreview);
		}
		
		if ($('pp-print')) {
			bbcjs.dom.addEventListener($('pp-print'), 'click', Common.onClickPrint);
		}
		
		if ($('pp-close')) {
			bbcjs.dom.addEventListener($('pp-close'), 'click', Common.onClickPrintPreviewClose);
		}
				
		if ($('banner') && helpKeyPage) {
			Common.helpListeners.push(bbcjs.dom.addEventListener(document, 'keypress', Common.onKeyDown));
			Common.helpListeners.push(bbcjs.dom.addEventListener(document, 'keydown', Common.onKeyDown));
			Common.helpListeners.push(bbcjs.dom.addEventListener(document.body, 'keypress', Common.onKeyDown));
			Common.helpListeners.push(bbcjs.dom.addEventListener(document, 'click', Common.onKeyDown));
			Common.helpListeners.push(bbcjs.dom.addEventListener(document.body, 'click', Common.onKeyDown
			));
			if (document.focus){
				document.focus();
			}			
		}
		
		
		
		// Determine session cookie settings
		if (typeof(DOCUMENT_URI) != "undefined") {
			if (DOCUMENT_URI.match("index.shtml")) {
				Common.sessionPath = DOCUMENT_URI.replace("index.shtml", "");
				Common.sessionName = "rawSessionIndex";
			}
			else {
				Common.sessionPath = DOCUMENT_URI;
				Common.sessionName = "rawSessionPage";
			}
		}
	},
	

	
	/**
	 * Function: onSubmitSearch
	 * 
	 * Description: Stops form submission in order to submit search using rewritten URL scheme
	 */
	onSubmitSearch: function(e){			
		bbcjs.dom.stopEvent(e); // Stop the form being submitted
		if (!$('search-box').value)
			alert(Common.emptySearchMessage);
		else{
			// Add forced rewrite inputs
			var cgiOpts = {};
			for (var i=0; i<e.target.elements.length; i++){
				if (bbcjs.dom.hasClassName(e.target.elements[i], 'forceRewrite')){
					cgiOpts[e.target.elements[i].name] = e.target.elements[i].value;
				}
			}		
			Common.rewriteSearch($('search-box').value, null, cgiOpts);
		}
			
	},
	
	/**
	 * Function: onClickPrintPreview
	 * 
	 * Description: Stops following of print preview link and instead opens print preview as a popup
	 */
	onClickPrintPreview: function(e){		
		bbcjs.dom.stopEvent(e); // Stop the link being followed
		openPrintPreviewPopup();
	},
	
	/**
	 * Function: onClickPrint
	 * 
	 * Description: Handles click print button. Prints page.
	 */
	onClickPrint: function(){		
		window.print();
	},
	
	/**
	 * Function: onClickPrintPreviewClose
	 * 
	 * Description: Handles click close button in print preview popup. Closes popup.
	 */
	onClickPrintPreviewClose: function(){		
		window.close();
	},
	
	/**
	 * Function: onKeyDown
	 * 
	 * Description: Handles any keydown events. If the key is 'H', then redirects browser to a help page.
	 * 
	 * @param {Object} e - the keydown event
	 */
	onKeyDown: function(e){		
		var keynum;
		
		if (e.keyCode && e.keyCode > 0) { // IE
			keynum = e.keyCode;
		}
		else if (e.which && e.which > 0) { // Netscape/Firefox/Opera
			keynum = e.which;
		}	
		
		// Key is the 'H' key
		if (keynum && (keynum == 72 || keynum == 104)){
			window.location = helpKeyPage;
		}else{			
			for (var i=0; i<Common.helpListeners.length; i++){
				bbcjs.dom.removeEventListener(Common.helpListeners[i]);
			}
		}
	},
	
	
	
	/**
	 * Function: rewriteSearch
	 * 
	 * Description: Performs rewritten search using supplied parameters
	 *
	 * @param {String} searchTerm - the term to display search results for
	 * @param {Object} url - (optional) the search URL to rewrite to
	 * @param {Object} cgiOpts - (optional) a key/value object of CGI paramters that will be rewritten as "/key-value"
	 */
	rewriteSearch: function(searchTerm, url, cgiOpts){	
		var searchUrl = url ? url : "/raw/pages/containing/";
		searchUrl += Common.encode(searchTerm);
		
		if (cgiOpts){
			for (key in cgiOpts){
				searchUrl += "/" + key + "-" + cgiOpts[key];
			}
		};
		
		// Do the rewritten search
		window.location = searchUrl;
	},
	
	/**
	 * Function: encode
	 * 
	 * Description: Entity-encodes any non-ASCII characters in search string
	 *
	 * @param {String} searchTerm - the term to display search results for
	 */
	encode: function(searchTerm){
		var term = searchTerm;
		
		// Remove any double quotes
		term = term.replace(/"/g,"");
		
		// Entity encode then URL escape any non-ASCII characters
		for (var i=0; i<term.length; i++){
			if (term.charCodeAt(i) > 127)
				term = term.replace(term.charAt(i), escape("&#" + term.charCodeAt(i) + ";"));
		}
		
		return term;
	},
	
	/**
	 * Function: addListenersToClass
	 * 
	 * Description: Adds event listeners to page elements in with the specified class name
	 *
	 * @param {String} classN - the class of elements to add the listeners to
	 * @param {String} eventType - the type of event to add
	 * @param {Function} handlerFunction - the function to call when the event is triggered
	 * @param {String} rootNode - (optional) root node in the document to search below for elements. If omitted, document is used.
	 */
	addListenersToClass: function(classN, eventType, handlerFunction, rootNode){
		var els = bbcjs.dom.getElementsByClassName(classN, null, rootNode);
		if (els.length > 0) {
			for (var i = 0; i < els.length; i++) {
				bbcjs.dom.addEventListener(els[i], eventType, handlerFunction);
			}
		}
	},

	/**
	 * Function: storeSessionData
	 * 
	 * Description: Saves specified data object as a per page session cookie
	 * 
	 * @param {Object} data - string or object containing data to save
	 * @return {Boolean} - true if cookie was saved successfully; false if data was too long to store in a cookie.
	 */
	storeSessionData: function(data){
		var str, success, kB;
		
		if (typeof(data) == 'object') {
			str = bbcjs.lib.string.obj2string(data);
		}else{
			str = data;
		}
		kB = (str.length/1024);
		if (kB >= 4){
			success = false;
		}else{
			success = bbcjs.cookies.setCookie(Common.sessionName, data, null, Common.sessionPath, 'bbc.co.uk');
		}
		return success;				
	},
	
	/**
	 * Function: loadSessionData
	 * 
	 * Description: Loads stored data from the per page session cookie
	 * 
	 * @return {Object} - data from session cookie
	 */
	loadSessionData: function(){		
		bbcjs.cookies.loadCookies();
		var data = null;
		if (bbcjs.cookies.cookieData[Common.sessionName]){		
			data = bbcjs.cookies.cookieData[Common.sessionName];						
		}			
		return data;
	},
	
	/**
	 * Function: clearSessionData
	 * 
	 * Description: Clears stored data from the per page session cookie
	 * 
	 */
	clearSessionData: function(){
		bbcjs.cookies.setCookie(Common.sessionName, null, null, Common.sessionPath, 'bbc.co.uk');
	},
	
	
	/**
	 * Namespace: Common.Popup
	 * 
	 * Description: Allows creation of a DHTML lightboxes containing at the given URL and of the given
	 * dimensions. If the client browser does not support lightbox functionality, then a popup window is
	 * opened containing the content. Also allows popups containing flash.
	 */
	Popup:{
		
		/*********************************************************************************************
		 * Properties
		 *********************************************************************************************/
		defaultPopupWidth: 920, // Height of popup if unspecified
		defaultPopupHeight: 690, // Width of popup if unspecified
		flashPopupURL: "/raw/flash_popup.shtml", // Server-relative URL of flash popup container page used for popup window
		
		// Browsers that do not support lightboxes
		unsupportedBrowsers: [
		    {
		        OS: 'Mac',
		        browser: 'Firefox',
				fixedVersion: 3
		    },
		    {
		        OS: 'an unknown OS',
		        browser: 'An unknown browser'
		    }
		],
		
		// Lightbox template for popup flash
		template: '<div class="bbcjsUiLightBoxDefault"> ' +
	        '<div id="lightbox-content">' +
	            '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ' +
	                'WIDTH="{l_width}" ' +
	                'HEIGHT="{l_height}" ' +
	                'id="{l_id}"> ' +
	                '<PARAM NAME=movie VALUE="{l_url}"> ' +
	                '<PARAM NAME=quality VALUE=high> ' +
	                '<EMBED  src="{l_url}" ' +
	                    'quality=high ' +
	                    'WIDTH="{l_width}" ' +
	                    'HEIGHT="{l_height}" ' +
	                    'NAME="{l_id}" ' +
	                    'TYPE="application/x-shockwave-flash" ' +
	                '</EMBED> ' +
	            '</OBJECT> ' +
	        '</div>' +
		'</div> ',
	
		/**********************************************************************************************
		 * Functions
		 *********************************************************************************************/
		
		/**
		 * Function: open
		 * 
		 * Description: Opens the specified page in a popup window .
		 * 
		 * @param {String} url - server-relative URL of the content page (e.g. "/raw/my_page.shtml")
		 * @param {Object} opts - optional parameters:
		 * 		{Integer} width - width of popup in pixels
		 * 		{Integer} height - height of popup in pixels
		 * 		{String} title - title for the popup window
		 */
		open: function(url, opts){
			Common.Popup.openWindow(url, opts);
		},
		
		/**
		 * Function: openFlash
		 * 
		 * Description: Opens the specified SWF in a popup of the specified dimensions. If the browser supports it,
		 * popup will be a DHTML lightbox, else a popup window will be used.
		 * 
		 * @param {String} url - server-relative URL of the swf file (e.g. "/raw/lib/my_flash.swf")
		 * @param {Object} opts - optional parameters:
		 * 		{Integer} width - width of popup in pixels
		 * 		{Integer} height - height of popup in pixels
		 * 		{String} title - title for the popup window
		 * 		{Boolean} forceWindow - if true, forces popup window instead of lightbox in lightbox-compatible browsers
		 * 		{Boolean} forceLightbox - if true, forces lightbox even in lightbox-incompatible browsers (for testing only)
		 * 		{Boolean} clickableMask - if true and a DHTML lightbox is opened, clicking the mask surrounding the lightbox will close the lightbox
		 */
		openFlash: function(url, opts){
			
			var options, pageURL, w, h;			
			opts ? options = opts : options = {};
			
			options.width ? w = options.width : w = Common.Popup.defaultPopupWidth;
			options.height ? h = options.height : h = Common.Popup.defaultPopupHeight;
			
			if (options.forceLightbox || (Common.Popup.supportsLightboxes() && !options.forceWindow)){
				Common.Popup.openFlashLightbox(url, w, h, options.clickableMask);
			}else{
				var pageURL = Common.Popup.flashPopupURL + "?url=" + escape(url) + "&width=" + options.width + "&height=" + options.height;
				if (options.title){
					pageURL += "&popupTitle=" + escape(options.title);
				}
				options.hasContainer = true;
				Common.Popup.openWindow(pageURL, options);
			}		
		},
		
		/**
		 * Function: openFlashLightbox
		 * 
		 * Description: Opens the specified SWF in a DHTML lightbox.
		 * 
		 * @param {String} url - server-relative URL of the swf file (e.g. "/raw/lib/my_flash.swf")
		 * @param {Integer} width - width of popup in pixels
		 * @param {Integer} height - height of popup in pixels
		 * @param {Boolean} clickableMask - (optional) if true and a DHTML lightbox is opened, clicking the mask surrounding the lightbox will close the lightbox
		 */
		openFlashLightbox: function(url, width, height, clickableMask){
		
	        // create the global JS lightbox
	        lightbox = new bbcjs.ui.LightBox(
	                [{
	                    l_width: width,
	                    l_height: height,
	                    l_id: "rawpopup",
	                    l_url: url
	                }], {
	                showNav: false,
	                width: width,
	                height: height,
	                borderWidth: 0,
	                boxBackground: '#000',
	                template: Common.Popup.template 
			});
		
		
	        // Open the light box
			  $('flash-content').style.visibility = 'hidden';
	        lightbox.open();

		     
			 // Create the global closePopup() function	 
		     closePopup = function(){
				Common.Popup.cleanUpFlash("rawpopup");
				$('flash-content').style.visibility = 'visible';
			 	lightbox.close();
			 }
			 
			 // Make lightbox opacity mask clickable to close lightbox
			 if (clickableMask) {
			 	var mask = $('bbcjsUiLightBoxMask');
			 	mask.style.cursor = 'pointer';
			 	bbcjs.dom.addEventListener(mask, 'click', closePopup);
			 }
		},
		
		/**
		 * Function: openWindow
		 * 
		 * Description: Opens a popup window using the specified URL and optional width and height
		 * 
		 * @param {String} url - server-relative URL of the content page (e.g. "/raw/my_page.shtml")	
		 * @param {Object} opts - optional parameters:
		 * 		{Integer} width - width of popup window in pixels
		 * 		{Integer} height - height of popup window in pixels
		 * 		{Boolean} scrollbars - flag to indicate if popup should have scrollbars
		 * 		{String} title - title of the popup window
		 * 		{Boolean} hasContainer - if true, indicates the specified URL already contains the URL of a popup container page
		 */
		openWindow: function (url, opts){
			
			var pop_window, x, y, w, h, sb, aw, ah, options, pageURL;		
			opts ? options = opts : options = {};
			
			// set defaults
		    x = 10, y = 10; // position
			options.width ? w = options.width : w = Common.Popup.defaultPopupWidth; // width
			options.height ? h = options.height : h = Common.Popup.defaultPopupHeight; // height
			options.scrollbars	? sb = "yes" : sb = "auto"; // scrollbars
		
		    // If browser supports screen object
		    if (window.screen) {
		        // Get screen width & height
		        aw = window.screen.availWidth;
		        ah = window.screen.availHeight;
				
				if (ah < h || aw < w){ 
					// If the available screen width or height is smaller than the specified dimensions, scale the window
		            w = parseInt(Math.floor(aw / (w/h)));
		            h = ah;
		        }
		
		        // Calculate x,y coordinates based on size
		        x = (aw - w) / 2;
		        y = (ah - h) / 2;
		    }
			
			if (options.hasContainer){
				pageURL = url;
			}else{
				pageURL = '/raw/popup.shtml?url=' + escape(url) + '&width=' + w + '&height=' + h;
				if (options.title){
					pageURL += "&popupTitle=" + options.title;
				}
			}		
		
		    // Open in new window
		    pop_window = window.open(
		        pageURL,
				"_blank",
		            'width=' + w +
		            ',height=' + h +
		            ',left=' + x +
		            ',screenX=' + x +
		            ',top=' + y +
		            ',screenY=' + y +
		            ',fullscreen=no' +
		            ',toolbar=no' +
		            ',location=no' +
		            ',directories=no' +
		            ',status=no' +
		            ',menubar=no' +
		            ',scrollbars='+ sb +
		            ',resizable=no'
		            );
		
		    // Name current window in case popup wants to talk back to it
		    self.name = "main";
			
			// Focus the popup window
			pop_window.focus();		
			
			// Create global closePopup() function
			closePopup = function(){			 	
				pop_window.close(); 				
			}
		},
		
		/**
		 * Function: openPrintPreview
		 * 
		 * Description: Opens the current page in a popup window in print preview mode
		 */
		openPrintPreviewPopup: function(){		
			Common.Popup.openWindow(PRINT_PREVIEW_URL,{scrollbars: true, hasContainer: true});
		},
		
		/**
		 * Function: supportsLightboxes
		 * 
		 * Description: Checks browser compatibility and returns true if the browser supports lightboxes.
		 * 
		 * @return {Boolean} - flag indicating if the browser supports lightboxes
		 */		
		supportsLightboxes: function(){		

		    var supported = true;
		
		    // for each unsupported browser
		    for (var i=0; i<Common.Popup.unsupportedBrowsers.length; i++){
		        // if this is an unsupported browser
		        if (Common.Popup.unsupportedBrowsers[i].OS == BrowserDetect.OS && Common.Popup.unsupportedBrowsers[i].browser == BrowserDetect.browser){
					if (Common.Popup.unsupportedBrowsers[i].fixedVersion && BrowserDetect.version >= Common.Popup.unsupportedBrowsers[i].fixedVersion){
						supported = true;
					}else{
						supported = false;	
					}		            
		            break;
		        }
		    }
			return supported;
		},
		
		/**
		 * Function: cleanUpFlash
		 * 
		 * Description: Cleans up the specified flash object on lightbox closing to avoid multiple layers of "ghost" audio in IE
		 * 
		  * @param {String} id - DOM Id of the flash object
		  */
		cleanUpFlash: function(id) {
		  // Get the lightboxed flash object
		  var object = $(id);
		  	// for each of its properties
			for (var x in object) {
				// try to null it
				try {object[x] = null;} 
				// ignoring exceptions thrown by those that are only getters
				catch (e) {};
			}
			// finally, null the object itself
			object = null;
		}
	
	},
		
	
	/**
	 * Namespace: Common.FormValidation
	 * 
	 * Description: Enables validation of HTML forms against specified criteria.
	 * If validation fails, stops form being submitted and displays validation error messages and highlights fields with errors.
	 */
	FormValidation:{
		
		/*********************************************************************************************
		 * Properties
		 *********************************************************************************************/
		
		// Key/value object where key is a form element DOM id and value is a validation criteria object
		form_criteria:{},
		
		
		/**********************************************************************************************
		 * Functions
		 *********************************************************************************************/
		
		/**
		 * Function: registerForm
		 * 
		 * Description: Registers a form for validation using specified validation criteria. 
		 * Adds onSubmit handler to intercept form submission and validate the form again the criteria.
		 * Adds onReset handler to clear errors on resetting form
		 * 
		 * @param {Element} form - form element to add validation to
		 * @param {Object} v_criteria - validation criteria against which to validate form. A key/value object where the key is the name 
		 * of the field to validate and the value is an object consisting of: 
		 * regex - the regex to validate it against
		 * message - error message to display if regex doesn't match
		 * 
		 */
		registerForm: function(form, v_criteria){		
			// Store validation criteria
			Common.FormValidation.form_criteria[form.id] = v_criteria;
				
			bbcjs.dom.addEventListener(form, 'submit', Common.FormValidation.onSubmit);
			bbcjs.dom.addEventListener(form, 'reset', Common.FormValidation.onReset);
		},
		
		/**
		 * Function: registerFieldInForm
		 * 
		 * Description: Adds validation criteria for given field in the given form
		 * 
		 * @param {Object} v_criteria - validation criteria. An object consisting of: 
		 * regex - the regex to validate it against
		 * message - error message to display if regex doesn't match
		 * @param {String} fieldName - name of the field to add the validation criteria to
		 * @param {Element} form - form element containing the field
		 */
		registerFieldInForm: function(v_criteria, fieldName, form){					
			if(!Common.FormValidation.form_criteria[form.id]){
				Common.FormValidation.form_criteria[form.id] = {};
			}
			Common.FormValidation.form_criteria[form.id][fieldName] = v_criteria;
		},
		
		/**
		 * Function: deregisterFieldInForm
		 * 
		 * Description: Removes validation criteria for given field in the given form
		 * 
		 * @param {String} fieldName - name of the field to remove the validation criteria from
		 * @param {Element} form - form element containing the field
		 */
		deregisterFieldInForm: function( fieldName, form){					
			if(Common.FormValidation.form_criteria[form.id] && Common.FormValidation.form_criteria[form.id][fieldName]){
				delete Common.FormValidation.form_criteria[form.id][fieldName];
			}			
		},
		
		/**
		 * Function: onSubmit
		 * 
		 * Description: Handles submission of registered form. Validates form against validation criteria.
		 * If validation fails, stops form being submitted.
		 * 
		 * @param {Element} e - submit event
		 */
		onSubmit: function(e){					
			if (!Common.FormValidation.validate(e.target)){
				// Stop submit event
				bbcjs.dom.stopEvent(e);
			}
		},
		
		/**
		 * Function: onReset
		 * 
		 * Description: Handles reset of registerd form. Removes any validation error messages when resetting.
		 * 
		 * @param {Element} e - reset event
		 */
		onReset: function(e){					
			Common.FormValidation.clearErrors(e.target);
		},
		
		/**
		 * Function: validate
		 * 
		 * Description: Validates specified form against validation criteria.
		 * Returns validility of form. If a validation error occurs handleValidationError will be called.
		 * 
		 * @param {Element} form - form element to validate
		 */
		validate: function(form){
			var valid = true;
			var errorMsgs = {};
			
			Common.FormValidation.clearErrors(form);

			for (var i=0; i<form.elements.length; i++){
				if (form.elements[i].name && Common.FormValidation.form_criteria[form.id][form.elements[i].name] 
				&& !bbcjs.forms.validateElement(form, form.elements[i].name, Common.FormValidation.form_criteria[form.id][form.elements[i].name].regex)){
					valid = false;
					errorMsgs[form.elements[i].name] = Common.FormValidation.form_criteria[form.id][form.elements[i].name].message;
				}
			}
			
			if (!valid){
				Common.FormValidation.handleValidationErrors(form, errorMsgs);
			}
					
			return valid;
		},
		
		/**
		 * Function: handleValidationErrors
		 * 
		 * Description: Handles form field validation errors. Displays validation error messages and highlights fields with errors.
		 * If an element exists with the DOM id "error-{form id}-{field name}", the validation error message will be inserting into that element.
		 * Otherwise, it will be inserted immediately after the field element.
		 * 
		 * @param {Element} form - form element containing invalid fields
		 * @param {Object} errors - error messages as key/value object where key is field name and value is error message
		 */
		handleValidationErrors: function(form, errors){
			var field;		
			for (var fieldName in errors){
				if (form[fieldName].length && !form[fieldName].tagName){
					field = form[fieldName][form[fieldName].length-1];
				}else{
					field = form[fieldName];
				}
				
				bbcjs.dom.addClassName(field, 'validation-error');	
				
				var msg = document.createElement('p');
				msg.innerHTML = errors[fieldName];
				msg.className = "validation-msg";
				if ($('error-' + form.id + '-' + fieldName)){
					$('error-' + form.id + '-' + fieldName).innerHTML = '';
					$('error-' + form.id + '-' + fieldName).appendChild(msg);
				}else{
					field.parentNode.insertBefore(msg, field.nextSibling);
				}				
			}
		},
		
		/**
		 * Function: clearErrors
		 * 
		 * Description: Clears error messages and error classes in specified form
		 * 
		 * @param {Element} form - form to clear errors in
		 */
		clearErrors: function(form){					
			var errMsgs = bbcjs.dom.getElementsByClassName('validation-msg', null, form);			
			for (var i=0; i<errMsgs.length; i++){
				errMsgs[i].parentNode.removeChild(errMsgs[i]);
			}
			
			var errFields = bbcjs.dom.getElementsByClassName('validation-error', null, form);			
			for (var i=0; i<errFields.length; i++){
				bbcjs.dom.removeClassName(errFields[i], 'validation-error');
			}
		}
	}			
};

/*
 * Alias Common functions into the global namespace for Flash
 */
openPopup = function(url, width, height, title, opts){
	var options; opts ? options = opts : options = {};
	options.width = width;
	options.height = height;
	options.title = title;
	return Common.Popup.open(url, options);
}
openFlashPopup = function(url, width, height, title, opts){
	var options; opts ? options = opts : options = {};
	options.width = width;
	options.height = height;
	options.title = title;
	return Common.Popup.openFlash(url, options);
}
openPrintPreviewPopup = function(){		
	return Common.Popup.openPrintPreviewPopup();
}
storeSessionData = function(data){
	return Common.storeSessionData(data);
}
loadSessionData = function(){
	return Common.loadSessionData();
}
clearSessionData = function(){
	return Common.clearSessionData();
}


/**
 * Compile-time executed code
 */
bbcjs.addOnLoadItem(Common.init);
/**
  * END
  */
