function winPic(id)
{
	window.open("newspic.php?id="+ id,"Newsbild","width=750,height=550,scrollbars=yes,status=yes,resizable=yes");
}

function Delete(bForm, id, strFile, strArea)
{
	if (bForm == 1) chk = confirm("Wollen Sie die markierten Einträge wirklich löschen?");
	else chk = confirm("Wollen Sie den ausgewählten Eintrag wirklich löschen?");

	if (chk == true)
	{
		if (bForm == 1) document.frmMain.submit();
		else window.location = strFile + '?action=loeschen&area=' + strArea + '&del_id[]=' + id;
	}
}

function liveTicker(liveTicker)
{
	helpwindow = window.open(liveTicker,"pophelp","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=1060, height=790,top=0,left=0");
	helpwindow.focus();
	return false;
}

function Meinungen(Meinungen)
{
	helpwindow = window.open(Meinungen,"pophelp","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=980, height=600,top=0,left=0");
	helpwindow.focus();
	return false;
}

function getPlayerAttributes(market_value)
{	
		if(market_value >= 100000000)	staerke = 89;
	else if(market_value >= 90000000)	staerke = 88;
	else if(market_value >= 80000000)	staerke = 87;
	else if(market_value >= 70000000)	staerke = 86;
	else if(market_value >= 60000000)	staerke = 85;
	else if(market_value >= 50000000)	staerke = 84;
	else if(market_value >= 46000000)	staerke = 83;
	else if(market_value >= 42000000)	staerke = 82;
	else if(market_value >= 38000000)	staerke = 81;
	else if(market_value >= 34000000)	staerke = 80;
	else if(market_value >= 30000000)	staerke = 79;
	else if(market_value >= 26000000)	staerke = 78;
	else if(market_value >= 22000000)	staerke = 77;
	else if(market_value >= 18000000)	staerke = 76;
	else if(market_value >= 14000000)	staerke = 75;
	else if(market_value >= 10000000)	staerke = 74;
	else if(market_value >= 8000000)	staerke = 73;
	else if(market_value >= 6000000)	staerke = 72;
	else if(market_value >= 5750000)	staerke = 71;
	else if(market_value >= 5250000)	staerke = 70;
	else if(market_value >= 4750000)	staerke = 69;
	else if(market_value >= 4500000)	staerke = 68;
	else if(market_value >= 4250000)	staerke = 67;
	else if(market_value >= 3750000)	staerke = 66;
	else if(market_value >= 3150000)	staerke = 65;
	else if(market_value >= 2900000)	staerke = 64;
	else if(market_value >= 2750000)	staerke = 63;
	else if(market_value >= 2600000)	staerke = 62;
	else if(market_value >= 2400000)	staerke = 61;
	else if(market_value >= 2250000)	staerke = 60;
	else if(market_value >= 1950000)	staerke = 59;
	else if(market_value >= 1825000)	staerke = 58;
	else if(market_value >= 1700000)	staerke = 57;
	else if(market_value >= 1550000)	staerke = 56;
	else if(market_value >= 1450000)	staerke = 55;
	else if(market_value >= 1350000)	staerke = 54;
	else if(market_value >= 1250000)	staerke = 53;
	else if(market_value >= 1150000)	staerke = 52;
	else if(market_value >= 1100000)	staerke = 51;
	else if(market_value >= 950000)		staerke = 50;
	else if(market_value >= 800000)		staerke = 49;
	else if(market_value >= 650000)		staerke = 48;
	else if(market_value >= 500000)		staerke = 47;
	else if(market_value >= 350000)		staerke = 46;
	else if(market_value >= 250000)		staerke = 45;
	else if(market_value >= 190000)		staerke = 44;
	else if(market_value >= 150000)		staerke = 43;
	else if(market_value >= 115000)		staerke = 42;
	else if(market_value >= 100000)		staerke = 41;
	else if(market_value >= 80000)		staerke = 40;
	else if(market_value >= 60000) 		staerke = 39;
	else 								staerke = 38;
	
	var attributes = new Object();
	attributes['staerke'] = staerke;
	attributes['technik'] = Math.round(staerke/100*25)+50;
	attributes['kondition'] = Math.round(staerke/100*25)+27;
	attributes['frische'] = 100;
	attributes['zufriedenheit'] = 50;

	return attributes;
}


	
function getHandMoney(market_value, transfer_money)
{
	var percent = 20 / 100 * Math.min(100,(100 / 10000000 * market_value));
	var hand_money = Math.round(transfer_money / 100 * percent/100)*100;
	
	return hand_money;
}


function getGameCount(salary)
{
	var gamecount = 0;
	if(salary < 1000) gamecount = 32;
	else if(salary < 20000) gamecount = 100;
	else if(salary < 40000) gamecount = 179;
	else if(salary < 50000) gamecount = 269;
	else gamecount = 358;
	
	return gamecount;
}

function getSalary(market_value)
{
	var salary = Math.round(Math.round((market_value/4)/179)/100)*100;
	
	if(salary < 500) salary = 500;
	//else if(salary > 139700) salary = 139700;
	
	return salary;
}

function getSalaryUpgrade(value)
{
	var salary = Math.round(Math.round(value*1.05)/100)*100;
	
	if(salary < 500) salary = 500;
	//else if(salary > 139700) salary = 139700;
	
	return salary;
}

function getGoalBonus(value)
{
	return Math.round(value/5);
}

function getGoalBonusUpgrade(value)
{
	return Math.round(Math.round(value*1.10)/100)*100;
}

function getCompensation(market_value, age, faktor)
{
	if(age < 20) age = 20;
	else if(age > 33) age = 33;

	return  Math.round(Math.round(market_value*35*Math.pow((1-(age/100)),6)*faktor)/100)*100;
}

function getMWFactor(value)
{
	return Math.round(((7*(Math.pow((1-(value/530000000)),6)))+1)*1000)/1000;
}

function quickRound(value,step)
{
	if (value % step != 0)
	{
		value = value + (step - (value % step));
	}
	return value;			
}

function euro_format(value)
{
	if(typeof value == 'undefined') return '-';
	return $().number_format(value,0,',','.') + '€';
}

function number_format(number, floats, csign, tsign) 
{
	if(typeof number == 'undefined') return '-';
	//a = Math.round(a * Math.pow(10, b)) / Math.pow(10, b);
	e = number + '';
	integer = e.split('.');
	if (!integer[0]) 
	{
		integer[0] = '0';
	}
	if (!integer[1])
	{
		integer[1] = '';
	}
	if (integer[1].length < floats)
	{
		g = integer[1];
		for (i=integer[1].length + 1; i <= floats; i++)
		{
			g += '0';
		}
		integer[1] = g;
	}
	if(tsign != '' && integer[0].length > 3)
	{
		h = integer[0];
		integer[0] = '';
		for(j = 3; j < h.length; j+=3)
		{
			i = h.slice(h.length - j, h.length - j + 3);
			integer[0] = tsign + i +  integer[0] + '';
		}
		j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3));
		integer[0] = j + integer[0];
	}
	csign = (floats > 0) ? csign : '';
	return integer[0] + csign + integer[1];
}

if (typeof jQuery != 'undefined') 
{
	(function( $ )
	{
		$.fn.highlight = function (text, o)
		{
			return this.each( function(){
				var replace = o || '<span class="highlight">$1</span>';
				$(this).html( $(this).html().replace( new RegExp('('+text+'(?![\\w\\s?&.\\/;#~%"=-]*>))', "ig"), replace) );
			});
		}

		$.fn.autolink = function ()
		{
			return this.each( function(){
				var re = /((http|https|ftp):\/\/[\w?=&.\/-;#~%-]+(?![\w\s?&.\/;#~%"=-]*>))/g;
				$(this).html( $(this).html().replace(re, '<a href="$1">$1</a> ') );
			});
		}

		$.fn.mailto = function () 
		{
			return this.each( function() {
				var re = /(([a-z0-9*._+]){1,}\@(([a-z0-9]+[-]?){1,}[a-z0-9]+\.){1,}([a-z]{2,4}|museum)(?![\w\s?&.\/;#~%"=-]*>))/g
				$(this).html( $(this).html().replace( re, '<a href="mailto:$1">$1</a>' ) );
			});
		}
		
		$.fn.number_format = function(number, params)
		{
			var sDefaults = 
				{			
				numberOfDecimals: 0,
				decimalSeparator: ',',
				thousandSeparator: '.',
				symbol: ''
				}

			var options = jQuery.extend(sDefaults, params);
			
			var decimals = options.numberOfDecimals;
			var dec_point = options.decimalSeparator;
			var thousands_sep = options.thousandSeparator;
			var currencySymbol = options.symbol;
			
			var exponent = '';
			var numberstr = number.toString();
			var eindex = numberstr.indexOf('e');	
			
			if (eindex > -1)
			{
				exponent = numberstr.substring(eindex);
				number = parseFloat(numberstr.substring(0, eindex));
			}
			else
			{
				numberstr = numberstr.replace(/[^0-9,]/g, '');
				number = parseInt(numberstr, 10);
			}

			if (decimals != null)
			{
				var temp = Math.pow(10, decimals);

				number = Math.round(number * temp) / temp;
			}

			var sign = number < 0 ? '-' : '';
			
			var integer = (number > 0 ? Math.floor(number) : Math.abs(Math.ceil(number))).toString();
			
			var fractional = number.toString().substring (integer.length + sign.length);
	
			dec_point = (dec_point != null) ? dec_point : ".";
			fractional = decimals != null && decimals > 0 || fractional.length > 1 ? (dec_point + fractional.substring(1)) : '';
			if (decimals != null && decimals > 0)
			{
				for (i = fractional.length - 1, z = decimals; i < z; ++i)
				{
					fractional += '0';
				}
			}

			thousands_sep = (thousands_sep != dec_point || fractional.length == 0) ? thousands_sep : null;
			if (thousands_sep != null && thousands_sep != '')
			{
				
				for (i = integer.length - 3; i > 0; i -= 3)
				{
					integer = integer.substring(0 , i) + thousands_sep + integer.substring (i);
				}

			}

			return sign + integer + fractional + exponent;
		};

		$.fn.ForceNumericOnly = function() 
		{
			return this.each(function()     
			{
				$(this).bind('keydown paste', function(e)         
				{
					if (e.shiftKey || e.ctrlKey || e.altKey) 
					{
						e.preventDefault();        
					} 
					else 
					{         
						var n = e.charCode || e.keyCode || 0;    
				
						if (!((n == 8)              // backspace       
						|| (n == 9)                	// tab     
						|| (n == 46)                // delete     
						|| (n >= 35 && n <= 40)     // arrow keys/home/end  
						|| (n >= 48 && n <= 57)     // numbers on keyboard         
						|| (n >= 96 && n <= 105)   // number on keypad     
						|| (n == 190)// thousend-dot      
						)) 
						{        
							e.preventDefault();     // Prevent character input      
						}     
					} 
				})
			})
		};
	})(jQuery);
}
