

	// ---------- Object singleton tpvB ----------
	// This function can directly used call  tpvb.functionName();
	// Ex: tpv.isValidDate(date);
    var tpvB = { 
    	// Global functions
	
			// -- insertOption --
			// Insert an option in a select dom object
			insertOption: function(obj,text,value,before) {
				
				if (obj != null) {
				
					// Create and element option
					var option=document.createElement('option');
					option.text	= text;
					option.value = value;
					
					if (before == '') { before = null; }
					
					try {
						obj.add(option,before); // Standards compliant
						}
					catch(ex) {
						obj.add(option); // IE only
						}
				}
			},

			// -- isValidDate --
			isValidDate: function(date) {
				RegExpformat = /^(([2][0]|[1][9])\d{2}-([0]\d|[1][0-2])-([0-2]\d|[3][0-1]))$/;
  				return RegExpformat.test(date);
			},
			
			// -- normalizeDate --
			// Add 0 to a date for pass it through url
			// Tranform: yyyy-m-d to yyyy-mm-dd
			normalizeDate: function(date) {
				var arr = date.split('-');
				if (arr[0].length == 1) { arr[0] = '0'+arr[0]; }
				if (arr[1].length == 1) { arr[1] = '0'+arr[1]; }
				if (arr[2].length == 1) { arr[2] = '0'+arr[2]; }
				date = arr[0]+'-'+arr[1]+'-'+arr[2];
				return date;	
 			},
			
			// -- sqlToDate --
			// Transform from sql format datestring to javascript date object
			sqlToDate: function(sqlDate) {
				var temp = [];
				var dateTemp = [];
				temp = sqlDate.split("-");
				dateTemp['year'] = parseInt(temp[0],10);
				dateTemp['month'] = parseInt(temp[1],10);
				dateTemp['day'] = parseInt(temp[2],10);
				dateObj = new Date();
				dateObj.setFullYear(dateTemp['year'],dateTemp['month']-1,dateTemp['day']);
				return dateObj;
			},
			
			// -- dateToSql --
			// Transform from javascript date object to sql format datestring
			dateToSql: function(date) {
				if (date != null) {
					if (typeof(date) == 'object') {
						return date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate();
					}
				}
			},
			
			end:false
			
    }
    // ---------- /Object singleton tpvB ----------   

    
    // ---------- Global functions --------------
	function resizeResultDisp(newHeight,iframeName) {
			if (iframeName == null) iframeName = 'resultado';
			document.getElementById(iframeName).height = newHeight;
	}
	// ---------- /Global functions --------------
	
    
    
    
    
    
    
    
    
    
    
    


