/***************mouseFollow******************/

var divName = 'dragDrop'; // div that is to follow the mouse
                       // (must be position:absolute)
                       
var act_WA = null;
var last_rot_mark_id = "";
var actOBJ = null;
                       
var offX = -20;
var offY = -20;

function mouseX(evt) {
	if (!evt) 
		evt = window.event;
	if (evt.pageX)
		return evt.pageX;
	else if (evt.clientX)
		return evt.clientX + (document.documentElement.scrollLeft ?  document.documentElement.scrollLeft : document.body.scrollLeft);
	else
		return 0;
}

function mouseY(evt){
	if (!evt)
		evt = window.event;
	if (evt.pageY)
		return evt.pageY;
	else if (evt.clientY)
		return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
	else
		return 0;
}

function follow(evt) {
	if (document.getElementById) {
		var obj = document.getElementById(divName).style;
		obj.visibility = 'visible';
		obj.left = (parseInt(mouseX(evt))+offX) + 'px';
		obj.top = (parseInt(mouseY(evt))+offY) + 'px';
		$('dragDrop').style.backgroundImage = act_WA.style.backgroundImage;
	}
}


function followMouse(e){
	//$('dragDrop').style.backgroundImage = e.style.backgroundImage;
	act_WA = e;
	document.onmousemove = follow;
}

function resetDragDropDiv(){
	//document.onmousemove = null;
	$('dragDrop').style.border='';
	tooltip.init();
	act_WA = null;
	$('dragDrop').style.backgroundImage = "";
	$('dragDrop').style.left = 0;
	$('dragDrop').style.top = 0;
	$('dragDrop').style.visibility = "hidden";
	tooltip.init();
}

/***************leiste_on_off******************/
function moveLeiste(id, x_on, x_off, y_on, y_off, force_on){
	if(!force_on){
		if($(id).style.zIndex == 0)
			$(id).style.zIndex = 1;
		else
			$(id).style.zIndex = 0;
	}else{
		$(id).style.zIndex = 1;
	}
	
	if(x_on > 0 && x_off > 0){
		var act_left = parseInt($(id).getStyle('left'));
		if(act_left == x_on){
			if(!force_on)
				new Effect.Move($(id), { x: x_off-x_on, y: 0, duration: 0.1 });
		}else{
			new Effect.Move($(id), { x: x_on-x_off, y: 0, duration: 0.1 });
		}
		return false;
	}else if(y_on > 0 && y_off > 0){
		var act_top = parseInt($(id).getStyle('top'));
		if(act_top == y_on){
			if(!force_on)
				new Effect.Move($(id), { x: 0, y: y_off-y_on, duration: 0.1 });
		}else{
			new Effect.Move($(id), { x: 0, y: y_on-y_off, duration: 0.1 });
		}
		return false;
	}
}

function moveLeiste_x(id, x_on, x_off, force_off, force_on, ZI){
	if(force_off){
			if(ZI == -1){
				$(id).style.zIndex = 0;
		
				if($(id+'_back'))
					$(id+'_back').style.zIndex = 0;
			}else{
				$(id).style.zIndex = ZI;
		
				if($(id+'_back'))
					$(id+'_back').style.zIndex = ZI;
			}
		
		if(isLeisteOnOff(id, x_on)){
			var act_left = parseInt($(id).getStyle('left'));
	
			new Effect.Move($(id), { x: x_off-act_left, y: 0, duration: 0.1 });

			if($(id+'_back'))
				new Effect.Move($(id+'_back'), { x: x_off-act_left, y: 0, duration: 0.1 });
		}
	}else if(force_on){
			if(ZI == -1){
				$(id).style.zIndex = 1;
		
				if($(id+'_back'))
					$(id+'_back').style.zIndex = 1;
			}else{
				$(id).style.zIndex = ZI;
		
				if($(id+'_back'))
					$(id+'_back').style.zIndex = ZI;
			}
		
		if(isLeisteOnOff(id, x_off)){
			
			var act_left = parseInt($(id).getStyle('left'));
	
			new Effect.Move($(id), { x: x_on-act_left, y: 0, duration: 0.1 });
		
			if($(id+'_back'))
				new Effect.Move($(id+'_back'), { x: x_on-act_left, y: 0, duration: 0.1 });
		}
	}else{
		if(ZI == -1){
			if($(id).style.zIndex == 0){
				$(id).style.zIndex = 1;
				if($(id+'_back'))
					$(id+'_back').style.zIndex = 1;
			}else{
				$(id).style.zIndex = 0;
				if($(id+'_back'))
					$(id+'_back').style.zIndex = 0;
			}
		}else{
			$(id).style.zIndex = ZI;
			if($(id+'_back'))
				$(id+'_back').style.zIndex = ZI;
		}
	
		var act_left = parseInt($(id).getStyle('left'));
	
		if(act_left == x_on){
			new Effect.Move($(id), { x: x_off-x_on, y: 0, duration: 0.1 });
			
			if($(id+'_back'))
				new Effect.Move($(id+'_back'), { x: x_off-x_on, y: 0, duration: 0.1 });
		}else{
			new Effect.Move($(id), { x: x_on-x_off, y: 0, duration: 0.1 });
			
			if($(id+'_back'))
				new Effect.Move($(id+'_back'), { x: x_on-x_off, y: 0, duration: 0.1 });
		}
	}
}

function isLeisteOnOff(id, l){
	return parseInt($(id).style.left)==l;
}

function moveLeiste_new(id, x, y, zIndex){
	$(id).style.zIndex = zIndex;
	new Effect.Move($(id), { x: x-parseInt($(id).getStyle('left')), y: y-parseInt($(id).getStyle('top')), duration: 0.1 });
	return false;
}

/***************rot_border******************/
function setRotBorder(id){
	if(last_rot_mark_id && $(last_rot_mark_id)){
		if(canAlphaPng){
			$(last_rot_mark_id).className = "lager_weapons_armors";
			$(id).className = "lager_weapons_armors_mousedown";
		}else{
			$(last_rot_mark_id).className = "lager_weapons_armors_ie6";
			$(id).className = "lager_weapons_armors_ie6_mousedown";
		}
		
		last_rot_mark_id = id;
	}else{
		if(canAlphaPng)
			$(id).className = "lager_weapons_armors_mousedown";
		else
			$(id).className = "lager_weapons_armors_ie6_mousedown";
		last_rot_mark_id = id;
	}
}

/***************mark_flag******************/
function setMark(id){
	if(canAlphaPng)
		$(id).innerHTML += '<img style="position:absolute; left:25px; top:24px;" src="/images/all/icons/erhalten_klein.png">';
	else
		$(id).innerHTML += '<div style="width:14px; height:15px; margin-left:25px; margin-top:24px; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/images/all/icons/erhalten_klein.png\')"></div>';
}

/********************* shining START ******************/

var shiningOBJ = Class.create({
	initialze: function(){
		this.last_shining_url = "a";
		this.shining_Start = null;
	},
	
	shiningStart: function(){
		this.shining_Start = new PeriodicalExecuter(function(){
			if($('lager_middle_links')){
				if(this.last_shining_url == "a"){
					//$('lager_middle_links').style.backgroundImage = 'url('+'images\/'+JS_lang+'\/buttons\/btn_start_b.png'+')';
					if(canAlphaPng)
						$('lager_toArena').className = "lager_middle_links_toArena_hover";
					else
						$('lager_toArena').className = "lager_middle_links_toArena_hover_ie6";
					this.last_shining_url = "b";
				}else{
					//$('lager_middle_links').style.backgroundImage = 'url('+'images\/'+JS_lang+'\/buttons\/btn_start_a.png'+')';
					if(canAlphaPng)
						$('lager_toArena').className = "lager_middle_links_toArena";
					else
						$('lager_toArena').className = "lager_middle_links_toArena_ie6";
					this.last_shining_url = "a";
				}
			}
		}, 1);
	}
});


/********************* shining END ******************/



/********************* Navi_worldmap START ******************/
var naviOBJ = Class.create({

	initialize: function(actX_min, actY_min, actX, actY){
		this.actX_min = actX_min;
		this.actY_min = actY_min;
		this.actX = actX;
		this.actY = actY;
		
		this.minLeft_min = 0;
		this.minLeft_max = 130;
		this.minTop_min = 0;
		this.minTop_max = 76;
		
		this.Left_min = -7178;
		this.Left_max = 0;
		this.Top_min = -4383;
		this.Top_max = 0;
		
		this.multiX = 8000/151;
		this.multiY = 4800/88;
		
		this.viewpoint = $('world_maps');
		this.fromMini = false;
		this.loadImages_map = new Array();
		this.loadImages_shadow = new Array();
	},
	
	checkLoadImages: function(nextX1, nextY1, nextX2, nextY2){
		for(var i=0; i<aAllProvinces.length; i++){
			if((nextX1 > parseInt(aAllProvinces[i].radiusX1) && nextX1 < parseInt(aAllProvinces[i].radiusX2) && (nextY1 > parseInt(aAllProvinces[i].radiusY1) && (nextY1 < aAllProvinces[i].radiusY2))) || (nextX2 > parseInt(aAllProvinces[i].radiusX1) && nextX2 < parseInt(aAllProvinces[i].radiusX2) && (nextY2 > parseInt(aAllProvinces[i].radiusY1) && (nextY2 < aAllProvinces[i].radiusY2)))){
				
				maps = aAllProvinces[i].maps;
				aMaps = maps.split("_");
				for(var j=0; j<aMaps.length; j++){
					if(loadedMaps.indexOf(parseInt(aMaps[j])) == -1 && this.loadImages_map.indexOf(parseInt(aMaps[j])) == -1){
						this.loadImages_map[this.loadImages_map.length] = parseInt(aMaps[j]);
					}
				}
				
				if(loadedShadows.indexOf(parseInt(aAllProvinces[i].id)) == -1 && this.loadImages_shadow.indexOf(parseInt(aAllProvinces[i].id))){
					this.loadImages_shadow[this.loadImages_shadow.length] = parseInt(aAllProvinces[i].id);
				}
			}
		}
	},
	
	/* function */
	moveToLeft: function(dis){
		this.loadImages_map = new Array();
		this.loadImages_shadow = new Array();
		move = true;
		
		if(this.actX + dis > this.Left_max){
			if(this.actX != this.Left_max){
				nextX = this.Left_max;
				nextY = Math.abs(this.actY);
			}else{
				move = false;
			}
		}else{
			nextX = Math.abs(this.actX + dis);
			nextY = Math.abs(this.actY);
		}
		
		if(move){
			this.checkLoadImages(nextX, nextY, nextX, nextY+417);
			
			if(this.loadImages_map.length == 0 && this.loadImages_shadow.length == 0){
				new Effect.Move(this.viewpoint, { x: (-1*nextX)-this.actX, y: 0, duration: 0.1 });
				$('mini_actPo').style.left = (nextX/this.multiX)+"px";
				this.actX = -1*nextX;
				this.actX_min = Element.positionedOffset($('mini_actPo')).left;
			}else{
				$('loading_layer').style.display = 'block';
				prel_internal = new Array();
				prel_internal_arguments = new Array();
				
				if(this.loadImages_map.length != 0){
					this.loadImages_map.each(function(id){
						preload_internal('/images/all/worldmap/tiles/'+aAllWorldmaps[id-1].mapImage, id, 'map');
						loadedMaps[loadedMaps.length] = id;
					});
				}
				
				if(this.loadImages_shadow.length != 0){
					this.loadImages_shadow.each(function(id){
						preload_internal('/images/all/worldmap/shadows/'+aAllProvinces[id-1].shadowImage, id, 'shadow');
						loadedShadows[loadedShadows.length] = id;
					});
				}
				
				actOBJ = this;
				
				new PeriodicalExecuter(function(pe){
					var finished = true;
					for(var i=0; i<prel_internal.length; i++){
						if(prel_internal[i].complete == false){
							finished = false;
						}
					}
				
					if(finished){
						pe.stop();
						setWorldBG();
						new Effect.Move(actOBJ.viewpoint, { x: (-1*nextX)-actOBJ.actX, y: 0, duration: 0.1 });
						$('mini_actPo').style.left = (nextX/actOBJ.multiX)+"px";
						actOBJ.actX = -1*nextX;
						actOBJ.actX_min = parseInt($('mini_actPo').style.left);
					}
				}, 0.1);
			}
		}
		return false;	
	},
	
	moveToRight: function(dis){
		this.loadImages_map = new Array();
		this.loadImages_shadow = new Array();
		move = true;
		
		if(this.actX - dis < this.Left_min){
			if(this.actX != this.Left_min){
				nextX = Math.abs(this.Left_min-822);
				nextY = Math.abs(this.actY);
			}else{
				move = false;
			}
		}else{
			nextX = Math.abs(this.actX-dis-822);
			nextY = Math.abs(this.actY);
		}
		
		if(((nextX-822)/this.multiX)-1 > this.minLeft_max){
			move = false;
		}
		
		if(move){
			this.checkLoadImages(nextX, nextY, nextX, nextY+417);
			
			if(this.loadImages_map.length == 0 && this.loadImages_shadow.length == 0){
				new Effect.Move(this.viewpoint, { x: (-1*(nextX-822))-this.actX, y: 0, duration: 0.1 });
				$('mini_actPo').style.left = ((nextX-822)/this.multiX)+"px";
				this.actX = -1*(nextX-822);
				this.actX_min = Element.positionedOffset($('mini_actPo')).left;
			}else{
				$('loading_layer').style.display = 'block';
				prel_internal = new Array();
				prel_internal_arguments = new Array();
				
				if(this.loadImages_map.length != 0){
					this.loadImages_map.each(function(id){
						preload_internal('/images/all/worldmap/tiles/'+aAllWorldmaps[id-1].mapImage, id, 'map');
						loadedMaps[loadedMaps.length] = id;
					});
				}
				
				if(this.loadImages_shadow.length != 0){
					this.loadImages_shadow.each(function(id){
						preload_internal('/images/all/worldmap/shadows/'+aAllProvinces[id-1].shadowImage, id, 'shadow');
						loadedShadows[loadedShadows.length] = id;
					});
				}
				
				actOBJ = this;
				
				new PeriodicalExecuter(function(pe){
					var finished = true;
					for(var i=0; i<prel_internal.length; i++){
						if(prel_internal[i].complete == false){
							finished = false;
						}
					}
				
					if(finished){
						pe.stop();
						setWorldBG();
						new Effect.Move(actOBJ.viewpoint, { x: (-1*(nextX-822))-actOBJ.actX, y: 0, duration: 0.1 });
						$('mini_actPo').style.left = ((nextX-822)/actOBJ.multiX)+"px";
						actOBJ.actX = -1*(nextX-822);
						actOBJ.actX_min = parseInt($('mini_actPo').style.left);
					}
				}, 0.1);
			}
		}
		return false;				
	},

	moveToTop: function(dis){
		this.loadImages_map = new Array();
		this.loadImages_shadow = new Array();
		move = true;
		
		if(this.actY + dis > this.Top_max){
			if(this.actY != this.Top_max){
				nextX = Math.abs(this.actX);
				nextY = this.Top_max;
			}else{
				move = false;
			}
		}else{
			nextX = Math.abs(this.actX);
			nextY = Math.abs(this.actY+dis);
		}
		
		if(move){
			this.checkLoadImages(nextX, nextY, nextX+822, nextY);
			
			if(this.loadImages_map.length == 0 && this.loadImages_shadow.length == 0){
				new Effect.Move(this.viewpoint, { x: 0, y: (-1*nextY)-this.actY, duration: 0.1 });
				$('mini_actPo').style.top = (nextY/this.multiY)+"px";
				this.actY = -1*nextY;
				this.actY_min = Element.positionedOffset($('mini_actPo')).top;
			}else{
				$('loading_layer').style.display = 'block';
				prel_internal = new Array();
				prel_internal_arguments = new Array();
				
				if(this.loadImages_map.length != 0){
					this.loadImages_map.each(function(id){
						preload_internal('/images/all/worldmap/tiles/'+aAllWorldmaps[id-1].mapImage, id, 'map');
						loadedMaps[loadedMaps.length] = id;
					});
				}
				
				if(this.loadImages_shadow.length != 0){
					this.loadImages_shadow.each(function(id){
						preload_internal('/images/all/worldmap/shadows/'+aAllProvinces[id-1].shadowImage, id, 'shadow');
						loadedShadows[loadedShadows.length] = id;
					});
				}
				
				actOBJ = this;
				
				new PeriodicalExecuter(function(pe){
					var finished = true;
					for(var i=0; i<prel_internal.length; i++){
						if(prel_internal[i].complete == false){
							finished = false;
						}
					}
				
					if(finished){
						pe.stop();
						setWorldBG();
						new Effect.Move(actOBJ.viewpoint, { x: 0, y: (-1*nextY)-actOBJ.actY, duration: 0.1 });
						$('mini_actPo').style.top = (nextY/actOBJ.multiY)+"px";
						actOBJ.actY = -1*nextY;
						actOBJ.actY_min = parseInt($('mini_actPo').style.top);
					}
				}, 0.1);
			}
		}
				
		return false;
	},
	
	moveToBottom: function(dis){
		this.loadImages_map = new Array();
		this.loadImages_shadow = new Array();
		move = true;
		
		if(this.actY - dis < this.Top_min){
			if(this.actY != this.Top_min){
				nextX = Math.abs(this.actX);
				nextY = Math.abs(this.Top_min-417);
			}else{
				move = false;
			}
		}else{
			nextX = Math.abs(this.actX);
			nextY = Math.abs(this.actY-dis-417);
		}
		
		if(((nextY-417)/this.multiY)-1 > this.minTop_max){
			move = false;
		}
		
		if(move){
			this.checkLoadImages(nextX, nextY, nextX+822, nextY);
			
			if(this.loadImages_map.length == 0 && this.loadImages_shadow.length == 0){
				new Effect.Move(this.viewpoint, { x: 0, y: (-1*(nextY-417))-this.actY, duration: 0.1 });
				$('mini_actPo').style.top = ((nextY-417)/this.multiY)+"px";
				this.actY = -1*(nextY-417);
				this.actY_min = Element.positionedOffset($('mini_actPo')).top;
			}else{
				$('loading_layer').style.display = 'block';
				prel_internal = new Array();
				prel_internal_arguments = new Array();
				
				if(this.loadImages_map.length != 0){
					this.loadImages_map.each(function(id){
						preload_internal('/images/all/worldmap/tiles/'+aAllWorldmaps[id-1].mapImage, id, 'map');
						loadedMaps[loadedMaps.length] = id;
					});
				}
				
				if(this.loadImages_shadow.length != 0){
					this.loadImages_shadow.each(function(id){
						preload_internal('/images/all/worldmap/shadows/'+aAllProvinces[id-1].shadowImage, id, 'shadow');
						loadedShadows[loadedShadows.length] = id;
					});
				}
				
				actOBJ = this;
				
				new PeriodicalExecuter(function(pe){
					var finished = true;
					for(var i=0; i<prel_internal.length; i++){
						if(prel_internal[i].complete == false){
							finished = false;
						}
					}
				
					if(finished){
						pe.stop();
						setWorldBG();
						new Effect.Move(actOBJ.viewpoint, { x: 0, y: (-1*(nextY-417))-actOBJ.actY, duration: 0.1 });
						$('mini_actPo').style.top = ((nextY-417)/actOBJ.multiY)+"px";
						actOBJ.actY = -1*(nextY-417);
						actOBJ.actY_min = parseInt($('mini_actPo').style.top);
					}
				}, 0.1);
			}
		}
		
		return false;
	},
	
	modiMiniMap: function(dX, dY){
		new Effect.Move($('mini_actPo'), { x: dX, y: dY, duration: 0.1 });
	},
	
	moveViewpoint: function(dis){
		alert(dis);
	}
});

/********************* Navi_worldmap END ******************/

/********************* Event START ******************/

/********************* Event END ******************/

/********************* COOKIE START ******************/
function setCookie(name, value, days){
	var expDate = new Date();
	expDate.setTime(expDate.getTime()+days*86400*1000);
	document.cookie = name + "="+ escape (value) + ";expires=" + expDate.toGMTString();
}

function getCookie(name){
	var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
	if(arr != null)
		return unescape(arr[2]);
	else
		return null;
}

function clearCookie(name){
	var expDate = new Date();
	expDate.setTime(expDate.getTime()-(1*86400*1000));
	var cval=getCookie(name);
	if(cval!=null)
		document.cookie= name + "="+cval+";expires="+expDate.toGMTString();
}

/********************* COOKIE END ******************/

/********************* POPUP WINDOW START ******************/

/*********************   POPUP WINDOW END  ******************/

/********************* SWITCH WEAPONS_ITEMS START ********************/

function switchWI(type){
	if(type == "weapons"){
		$('lager_weaponItem_nav_weapon').className='lager_weaponItem_nav lager_weaponItem_nav_weapon text_beige_11';
		$('lager_weaponItem_nav_weapon').style.cursor="default";
			
		$('lager_weaponItem_nav_item').className='lager_weaponItem_nav lager_weaponItem_nav_item_off text_beige_11';
		$('lager_weaponItem_nav_item').style.cursor="pointer";
		
		if(canAlphaPng){
			$('lager_item').style.display='none';
			$('lager_item').style.zIndex='0';
			$('lager_weapon').style.display='block';
			$('lager_weapon').style.zIndex='1';
			$('lager_Items_inGame').style.display='none';
			$('lager_Weapons_inGame').style.display='block';
		}else{
			$('lager_item').style.display='none';
			$('lager_item').style.zIndex='0';
			$('lager_weapon').style.display='block';
			$('lager_weapon').style.zIndex='1';
			$('lager_Items_inGame_back').style.display='none';
			$('lager_Items_inGame').style.display='none';
			$('lager_Weapons_inGame_back').style.display='block';
			$('lager_Weapons_inGame').style.display='block';
		}
		
	}else{
		$('lager_weaponItem_nav_item').className='lager_weaponItem_nav lager_weaponItem_nav_item text_beige_11';
		$('lager_weaponItem_nav_item').style.cursor="default";
			
		$('lager_weaponItem_nav_weapon').className='lager_weaponItem_nav lager_weaponItem_nav_weapon_off text_beige_11';
		$('lager_weaponItem_nav_weapon').style.cursor="pointer";
		
		if(canAlphaPng){
			$('lager_weapon').style.display='none';
			$('lager_weapon').style.zIndex='0';
			$('lager_item').style.display='block';
			$('lager_item').style.zIndex='1';
			$('lager_Weapons_inGame').style.display='none';
			$('lager_Items_inGame').style.display='block';
		}else{
			$('lager_weapon').style.display='none';
			$('lager_weapon').style.zIndex='0';
			$('lager_item').style.display='block';
			$('lager_item').style.zIndex='1';
			$('lager_Weapons_inGame_back').style.display='none';
			$('lager_Weapons_inGame').style.display='none';
			$('lager_Items_inGame_back').style.display='block';
			$('lager_Items_inGame').style.display='block';
		}
		
	}
}

function switchWI_nav_bg(e, type, name){
	if(name == 'weapons'){
		if(type == "hover" && e.style.cursor == 'pointer'){
			e.className = 'lager_weaponItem_nav lager_weaponItem_nav_weapon_hover text_beige_11';
		}else{
			if(e.style.cursor == 'pointer')
				e.className = 'lager_weaponItem_nav lager_weaponItem_nav_weapon_off text_beige_11';
		}
	}else{
		if(type == "hover" && e.style.cursor == 'pointer'){
			e.className = 'lager_weaponItem_nav lager_weaponItem_nav_item_hover text_beige_11';
		}else{
			if(e.style.cursor == 'pointer')
				e.className = 'lager_weaponItem_nav lager_weaponItem_nav_item_off text_beige_11';
		}
	}
}

/********************* SWITCH WEAPONS_ITEMS END ********************/

/********************* MESSAGE BOX START ************************/
function showMsgBox(msg){
	$('msgbox').innerHTML = msg;
	$('msgbox').show();
}

function closeMsgBox(){
	$('msgbox').hide();
}

/********************* MESSAGE BOX END ************************/

function removeFocus(event){
		var element = event.element();
		element.blur();
}

function checkTextLength(e, maxLength, disID){
	if(e.value.length > maxLength){
		e.value = e.value.substr(0, maxLength);
	}

	if(disID){
		$(disID).innerHTML = maxLength-e.value.length;
	}
}

function showGBLayer(id){
	$('busy_layer').show();
	$(id).show();
}

function fRandomBy(under, over){
	switch(arguments.length){
		case 1: return parseInt(Math.random()*under+1);
		case 2: return parseInt(Math.random()*(over-under+1) + under);
		default: return 1;
	}
}

function thousandSeparator(n,lang,sep) {
	var sRegExp = new RegExp('(-?[0-9]+)([0-9]{3})'), sValue=n+'';
	
	if(lang == 'us' || lang == 'en'){
		if(sep === undefined){
			sep=',';
		}
	}else{
		if(sep === undefined){
			sep='.';
		}	
	}
	
	while(sRegExp.test(sValue)){
		sValue = sValue.replace(sRegExp, '$1'+sep+'$2');
	}
	return sValue;
}

/*************** loading time *******************************/
function saveLoadingTime(id){
	new Ajax.Request('index.es?saveLoad=1', {
		method: 'post',
		parameters: 'id='+id,		
		encoding:'UTF-8'
	});
}

function fireEvent(element,event){
	if (document.createEventObject){
		// dispatch for IE
		var evt = document.createEventObject();
		return element.fireEvent('on'+event,evt)
	}else{
		// dispatch for firefox + others
		var evt = document.createEvent("HTMLEvents");
		evt.initEvent(event, true, true ); // event type,bubbling,cancelable
		return !element.dispatchEvent(evt);
	}
}


function makeWindow(url, w, h, scroll) {
	var l = (window.screen.width - w) / 2;
	var t = (window.screen.height - h) / 2;
	if(scroll){
		var w = window.open(url, 'WOT', "width=" + w + ",height=" + h + ",left=" + l + ",top=" + t + ",scrollbars=yes");
	}else{
		var w = window.open(url, 'WOT', "width=" + w + ",height=" + h + ",left=" + l + ",top=" + t + ",scrollbars=no");	
	}

	if (!w){
		showMessageBox(popupBlocker, "messageBox_default");
		return false;
	}else{
		return w;
	}
}