	// number_format(number, decimals, comma, formatSeparator)
	function number_format(a, b, c, d) {
		a = Math.round(a * Math.pow(10, b)) / Math.pow(10, b);
		e = a + '';
		f = e.split('.');
		if(!f[0]) f[0] = '0';
		if(!f[1]) f[1] = '';
		if(f[1].length < b){
			g = f[1];
			for(i = f[1].length + 1; i <= b; i++) {
				g += '0';
			}
			f[1] = g;
		}
		if(d != '' && f[0].length > 3) {
			h = f[0];
			f[0] = '';
			for(j = 3; j < h.length; j += 3) {
				i = h.slice(h.length - j, h.length - j + 3);
				f[0] = d + i +  f[0] + '';
			}
			j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3));
			f[0] = j + f[0];
		}
		c = (b <= 0) ? '': c;
		return f[0] + c + f[1];
	}

	function cleanValue(value) {
		var cleanValue = '';
	
		if(value != null && value.length > 0) {
			cleanValue = value.replace(/_/g, ' ');
			cleanValue = cleanValue.toLowerCase();
		}
		
		return cleanValue;
	}
	
	/**
	 * creates the head part of the flyout
	 */
	function createBegin( sTitle )
	{
		return '<div class="top">&nbsp;</div>' +
				'<div class="center">' +
				'<table width="250" cellpadding="0" cellspacing="0" border="0">' +
				'<tr>' +
				'<td align="left" width="70%" class="title">'+sTitle+'</td>'+
				'<td valign="top" align="right" with="20%" colspan="2" class="closeBtn" onclick="ew.hide()"><a href="javascript:ew.hide();" class="closeStr">Schliessen</a> <img class="closeImg" name="closeImg" src="' + localVar.hostUrl + '/img/'+ localVar.customer +'/'+localVar.flyoutStyle+'/close_btn.gif" height="11" width="11"></td>' +
				'</tr>' +
				'<tr class="cutLine"><td colspan="2" class="cutLine"></td></tr>';
	}
	
	/**
	 * creates the end part of the flyout
	 */
	function createEnd()
	{
		return '</table></div>'+
				'<div class="bottom">&nbsp;</div>';
	}
	
	/**
	 * creates the title of the flyout
	 * @param {string}
	 * 		Title of the flyout
	 */
	function createTitlePart(title) {
		if(title != null && title.length > 0)
		{
			return '<tr><td><h2>' + title + '</h2></td><td>&nbsp;</td></tr>';
		}
		
		return "";
	}

	/**
	 * creates the image 
	 * @param {string}
	 * 		Link to the image
	 */
	function createLayoutImage( link )
	{
		if( link != null && link.length > 0)
		{
			return '<tr align="center"><td colspan="2"><img style="margin-top:3px;" src="'+ link +'" height="100" /></td></tr>';
		}
	}
	
	/**
	 * creates an item in the table
	 * @param {string}
	 * 		Content of td
	 */
	function createItem( str )
	{
		if(str != null && str.length > 0)
		{
			return '<tr><td>' + str + '</td><td>&nbsp;</td></tr>';
		}
		
		return "";
	}
	
	/**
	 * creates a simple link
	 * @param {string} link
	 * 		link
	 * @param {string}
	 * 		Link name
	 */
	function createLink( link, str )
	{
		if(link != '' && link != null && link.length > 0)
		{
			return '<tr><td colspan="2" align="right" width="100%"><a target="_blank" href="'+ link +'">' + str + '</a></td></tr>';
		}
		
		return "";
	}
	
	/**
	 * creates a simple link that fires an
	 * XMLHttp request
	 * 
	 * @requires ajax_load.js
	 * @param {string} link
	 * 		Link
	 * @param {string}
	 * 		Link name
	 */
	function createAjaxLink( link, str )
	{
		if(link != '' && link != null && link.length > 0)
		{
			/* return '<tr><td colspan="2" align="right" width="100%"><a href="#mapdetail" onclick="window.open('+ "'" + link + "'" + ')">' + str + '</a></td></tr>';*/
			return '<tr><td colspan="2" align="right" width="100%"><a href="#mapdetail" onclick="ajaxLoad('+ "'" + link + "'" +')">' + str + '</a></td></tr>'; 
		}
		
		return "";
	}

	/**
	 * creates the title of the flyout
	 * @param {array}
	 * 		Array containing the infos
	 */	
	function createAddressPart(address)
	{
		var sAddress = '';
	
		if(address != null) {
			var sCity    = address['city'] 	 != null ? address['city'] : '';
			var sCountry = address['country']!= null ? countries[ address['country'] ]: '';

			
			sAddress  = sCity;
			sAddress += sAddress.length > 0 ? (sCountry.length > 0 ? (', ' + sCountry) : '') : sCountry;
			
			if(sAddress.length > 0)
			{
				sAddress = '<tr><td colspan="2">' + sAddress + '</td></tr>' +
						'<tr class="cutLine"><td colspan="2" class="cutLine"></td></tr>';
			}
		}
		
		return sAddress;
	}


	/**
	 * creates the title of the flyout
	 * @param {array}
	 * 		Array containing the infos
	 */	
	function createFactoryDataPart( data )
	{
		var sData = '';
		
		if(data != null)
		{
			var sData 	= (data['gwh'] ? '<br/>GWh ' + data['gwh'] : '')
						+ (data['mw'] ? '<br/>MW ' + data['mw'] : '')
						+ '<br/>' + types[ data['type'] ];
		}
		
		return sData;
	}
	


	function flyout(data) {
		if (data['nok'] == 1){
			var link = createLink(data['link'], "Detailinformationen");
		} else {
			var link = createAjaxLink(data['link'], "Detailinformationen");
		}
		var sFlyout = 
			createBegin(data['name'])  +
			createLayoutImage(localVar.hostUrl + '/img/thumbnails/'+ data['image']) +
			createItem(data['company'])+
			createAddressPart(data)         +
			link         +
			//createAjaxLink(data['link'], "Ansehen")         +
			createEnd();	
		return sFlyout;
	}

