/*!
 * Ext JS Library 3.0.0
 * Copyright(c) 2006-2009 Ext JS, LLC
 * licensing@extjs.com
 * http://www.extjs.com/license
 */
 
/* <!> uses the show() and hide() functions defined inside the mt_functions.js file */

var MX_CALENDAR_PROMO = Ext.extend(Ext.util.Observable, {
    constructor: function(config){
        this.addEvents('finished'); // specify the events we're going to fire
        MX_CALENDAR_PROMO.constructor.call(this, config);
    },
    
    create: function(pid, uid, i, value){
		var v = value.split('|||',8);
			
		var label_b = '';
		var label_m = '';
		var label_e = '';
	
		if (v.length == 8){
			label_b = v[0];
			label_m = v[2];
			label_e = v[1];
		}
		
		var db = v[v.length - 5].split('-',3);
		var de = v[v.length - 4].split('-',3);
		var idTO = v[v.length - 2];
		var pidTO = v[v.length - 3];
		 
		var html = '';
		
		if (v[v.length - 5] != v[v.length - 4]){
			// years -> db[0] & de[0]
			var s = "";
			if (v[7] == 1){
				s = '<div class="mt_promo_block_mx_calendar_dbl mt_promo_block_field">'+label_b+'</div>'+
						'<div class="mt_promo_block_mx_calendar_db mt_promo_block_field">'+parseFloat(db[2])+' '+intToMonth(db[1])+'</div>';
			}
			else{
				if (intToMonth(db[1]) == intToMonth(de[1])){
					s = '<div class="mt_promo_block_mx_calendar_dbl mt_promo_block_field">'+label_b+'</div>'+
						'<div class="mt_promo_block_mx_calendar_db mt_promo_block_field">'+parseFloat(db[2])+'</div>'+
						'<div class="mt_promo_block_mx_calendar_del mt_promo_block_field">'+label_e+'</div>'+
						'<div class="mt_promo_block_mx_calendar_de mt_promo_block_field">'+parseFloat(de[2])+' '+intToMonth(de[1])+'</div>';
				}
				else{
					s = '<div class="mt_promo_block_mx_calendar_dbl mt_promo_block_field">'+label_b+'</div>'+
						'<div class="mt_promo_block_mx_calendar_db mt_promo_block_field">'+parseFloat(db[2])+' '+intToMonth(db[1])+'</div>'+
						'<div class="mt_promo_block_mx_calendar_del mt_promo_block_field">'+label_e+'</div>'+
						'<div class="mt_promo_block_mx_calendar_de mt_promo_block_field">'+parseFloat(de[2])+' '+intToMonth(de[1])+'</div>';
				}
			}
			html = '<div onmouseover="show(this);" onmouseout="hide(this);" '+
						'onclick="window.location.href=\'http://'+window.location.hostname+
							'/index.php?id='+pidTO+'&idObject='+idTO+'\';">'+
							s+
					  '</div>';
		}
		else{
			html = '<div onmouseover="show(this);" onmouseout="hide(this);" '+
					'onclick="window.location.href=\'http://'+window.location.hostname+
						'/index.php?id='+pidTO+'&idObject='+idTO+'\';">'+
					'<div class="mt_promo_block_mx_calendar_dml mt_promo_block_field">'+label_m+'</div>'+
					'<div class="mt_promo_block_mx_calendar_dm mt_promo_block_field">'+parseFloat(db[2])+' '+intToMonth(db[1])+'</div>'+
				  '</div>'
		}
		
		this.panel = new Ext.Panel({ 
			id: 'mt_promo_block_mx_calendar-'+uid+'-'+i,
			cls: 'mt_promo_block_mx_calendar mt_promo_block_field',
			html: html
		});
		
		this.fireEvent('finished', this.panel);
    }
});
