var AutoFocusElement = null;
var DebugHost = null;

function IsDebugHost()
{
	if (DebugHost==null || DebugHost==''){return false}
	return location.host.indexOf(DebugHost)==0;
}

var CanUseTransparency = true;

function CheckUseActiveX()
{
	/*var h = getXMLHTTP();
	if (h == null)
	{
		CanUseTransparency = false;
	}	*/
}
CheckUseActiveX();

function H(id, path)
{
document.getElementById('bimg_' + id + '_1').src = path + "lhn.gif";
document.getElementById('bimg_' + id + '_2').src = path + "rhn.gif";
}

function U(id, path)
{
document.getElementById('bimg_' + id + '_1').src = path + "ln.gif";
document.getElementById('bimg_' + id + '_2').src = path + "rn.gif";
}

function Hh(id, path)
{
document.getElementById('bimg_' + id + '_1').src = path + "lhn.gif";
document.getElementById('bimg_' + id + '_2').src = path + "rnhh.gif";
}

function Uh(id, path)
{
document.getElementById('bimg_' + id + '_1').src = path + "ln.gif";
document.getElementById('bimg_' + id + '_2').src = path + "rnh.gif";
}

function C(el,url)
{
el.src = url;
}

function list(url,n)
{
for(i = 1; i <= n; i++)
{
document.write("<img src=\"");
document.write(url);
document.write("\">");
}
}

function to(element,n)
{
parent.document.forms[0].elements[element].value = n;
parent.cClick();
}

function InvertCheckbox(field) 
{
	if (field)
	{
		if (field.length)
		{
			var i; 
			for (i = 0; i < field.length; i++) 
			{ 
				field[i].checked = !field[i].checked; 
			}
		}
		else
		{
			field.checked=!field.checked;
		}
	}
} 

function ChangeCoords2(x, y, warp)
{
	var w = 0;
	w = warp-1; //Wegen der Konvertierung Sting zu Zahl
	w = w + 1;

	ChangeCoords3(0, 0, x - w, y - w);
	ChangeCoords3(1, 0, x,     y - w);
	ChangeCoords3(2, 0, x + w, y - w);

	ChangeCoords3(0, 1, x - w, y    );
	ChangeCoords3(2, 1, x + w, y    );

	ChangeCoords3(0, 2, x - w, y + w);
	ChangeCoords3(1, 2, x,     y + w);
	ChangeCoords3(2, 2, x + w,   y + w);
}

function ChangeCoords3(CellX, CellY, NewX, NewY)
{
	document.getElementById('Cell_' + CellX + '_' + CellY).innerHTML=NewX+'|'+NewY;
}

function Redirect(url, timeout)
{
	setTimeout ("_Redirect('" + url + "')",timeout);
}

function _Redirect(url)
{
	location.href=url;
}

function LN(node)
{
	document.write('<small>');
	document.write('<font color=#666666>[</font>');
	document.write('<a href="LanguageEdit.aspx?n=' + node + '" target="langedit"><font color=orange>E</font></a>');
	document.write('<font color=#666666>]</font>');
	document.write('</small>');
}

function GetTopWindow()
{
	var p = window;
	while (true)
	{
		if (p.parent==null || (p==top))
		{
			return p;
		}
		else
		{
			if (IsForeignFrame(p.parent))
			{
				return p;
			}
			else
			{
				p = p.parent;
			}
		}
	}

	return window;
}

function IsForeignFrame(p)
{
	try
	{
		if (p)
			if (p.game_play_iframe) return true;
	}
	catch (e)
	{
		return true;
	}

	return false;
}

function NavigateFrame(url, name)
{
	var win = GetTopWindow();
	win.location.href=url;
}

function SetTopFrameName()
{
	var win = GetTopWindow();
	win.name = 'stne_top';
}

SetTopFrameName();

function insertText(el, aTag, eTag) {
  //var input = el;
  //eTag='';
  var input = document.getElementById(el);
  input.focus();
  /* für Internet Explorer */
  if(typeof document.selection != 'undefined') {
    /* Einfügen des Formatierungscodes */
    var range = document.selection.createRange();
    var insText = range.text;
    range.text = aTag + insText + eTag;
    /* Anpassen der Cursorposition */
    range = document.selection.createRange();
    if (insText.length == 0) {
      range.move('character', -eTag.length);
    } else {
      range.moveStart('character', aTag.length + insText.length + eTag.length);      
    }
    range.select();
  }
  /* für neuere auf Gecko basierende Browser */
  else if(typeof input.selectionStart != 'undefined')
  {
    /* Einfügen des Formatierungscodes */
    var start = input.selectionStart;
    var end = input.selectionEnd;
    var insText = input.value.substring(start, end);
    input.value = input.value.substr(0, start) + aTag + insText + eTag + input.value.substr(end);
    /* Anpassen der Cursorposition */
    var pos;
    if (insText.length == 0) {
      pos = start + aTag.length;
    } else {
      pos = start + aTag.length + insText.length + eTag.length;
    }
    input.selectionStart = pos;
    input.selectionEnd = pos;
  }
  /* für die übrigen Browser */
  else
  {
    /* Abfrage der Einfügeposition */
    var pos;
    var re = new RegExp('^[0-9]{0,3}$');
    while(!re.test(pos)) {
      pos = prompt("Einfügen an Position (0.." + input.value.length + "):", "0");
    }
    if(pos > input.value.length) {
      pos = input.value.length;
    }
    /* Einfügen des Formatierungscodes */
    var insText = prompt("Bitte geben Sie den zu formatierenden Text ein:");
    input.value = input.value.substr(0, pos) + aTag + insText + eTag + input.value.substr(pos);
  }
}

document.observe("dom:loaded", function() {
	if(Prototype.Browser.IE6)
	{
		var elArray = $$('input');
		var i=0;
		for(i=0;i<elArray.length;i++)
		{
			var el = elArray[i];
			var type = el.getAttribute('type').toLowerCase();
			if(type=='text' || type=='password' || el.className=='button2')
			{
				PrepareFormHighlight(el);
				el.setStyle({marginTop:'-1px',marginBottom:'-1px'});
			}
			
		}

		elArray = $$('textarea');
		for(i=0;i<elArray.length;i++)
		{
			var el = elArray[i];
			PrepareFormHighlight(el);
			el.setStyle({marginTop:'-1px',marginBottom:'-1px'});
		}

		elArray = $$('select');
		for(i=0;i<elArray.length;i++)
		{
			var el = elArray[i];
			PrepareFormHighlight(el);
		}

		var bodyEl = $('body');
		if(bodyEl)
			for(i=0;i<bodyEl.childNodes.length;i++)
			{
				var el = bodyEl.childNodes[i];
				if(el.tagName)
					if(el.tagName.toLowerCase()=='table')
					{
						$(el).addClassName('indent');
					}
			}

		elArray = $$('#map td.cell'); //Bug: Selektiert nicht den Orbit
		for(i=0;i<elArray.length;i++)
		{
			var el = elArray[i];
			Event.observe(el, 'mouseover', function(){this.addClassName('cell_hover');});
			Event.observe(el, 'mouseout', function(){this.removeClassName('cell_hover');});
		}
	}

	if(AutoFocusElement)AutoFocusElement.focus();
	
//	this will iterate with each element with the class 'ie-fix-opacity' and add an IE filter,
		//	replacing the background-image for the filter of that image
		var version = parseFloat(navigator.appVersion.split('MSIE')[1]);
		if ((version >= 5.5) && (version < 7) && (document.body.filters)) {
			document.getElementsByClassName('ddd').each(function(poElement){
				// if IE5.5+ on win32, then display PNGs with AlphaImageLoader
				var cBGImg = poElement.currentStyle.backgroundImage;
				var cImage = cBGImg.substring(cBGImg.indexOf('"') + 1, cBGImg.lastIndexOf('"'));
				poElement.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + cImage + "', sizingMethod='scale')";
				poElement.style.backgroundImage = "none";
			});
		}

});

function PrepareFormHighlight(el)
{
	Event.observe(el, 'mouseover', function(){this.addClassName('input_mouseover')});
	Event.observe(el, 'mouseout', function(){this.removeClassName('input_mouseover')});
	Event.observe(el, 'focus', function(){this.addClassName('input_focus')});
	Event.observe(el, 'blur', function(){this.removeClassName('input_focus')});
}

function PulsateEffect(id, count)
{
	document.observe("dom:loaded", function()
	{
		var el = $(id);
		if(!count) count = 3;
		Effect.Pulsate(id, { pulses: count, duration: 2*count,from:0.3 });

		//alert(el);
	});
}

function BlinkEffectClass(el)
{
	this.el = $(el);
	this.el.BlinkEffectObject = this;
	this.state = true;
	//this.timer = -1;
	this.count=0;
	this.callback = function()
	{
		var interval;
		if (this.state)
		{interval=300;this.el.setStyle({visibility:'hidden'})}else{interval=1000;this.el.setStyle({visibility:'visible'})}
		this.state=!this.state;
		//alert(this.state);
		//setTimeout(this.callback, 1000);
		this.next(interval);
	}
	//alert(this.count);
	
	this.next = function(interval)
	{
		setTimeout("$('"+this.el.id+"').BlinkEffectObject.callback.call($('"+this.el.id+"').BlinkEffectObject)", interval);
	}
	this.next(1000);
	
}

function BlinkEffect(id, count)
{
	document.observe("dom:loaded", function()
	{
		var el = $(id);
		if(!count) count = 3;
		//Effect.Blink(id, { pulses: count, duration: 2*count,from:0.3 });
		new BlinkEffectClass(id);
		//alert(el);
	});
}

function ScrollToEffect(el)
{
	document.observe("dom:loaded", function()
	{
		el = $(el);
		Effect.ScrollTo(el, { duration: 2.0});
	});
}

function PuffEffect(el)
{
	document.observe("dom:loaded", function()
	{
		el = $(el);
		var t = Math.floor((Math.max(Math.min(document.viewport.getHeight(), $(document.body).getHeight()), 100) / 2) - (el.getHeight() / 2));
		el.setStyle({width: document.viewport.getWidth()+'px', top: t+'px'});
		setTimeout(function(){Effect.Puff(el, { duration: 1})}, 3000);
	});
}



/**********************************
* Dialog-Functions
**********************************/

function OpenParentDialog(url, name, width, height)
{
	GetCurrentDialog().parentWindow.OpenDialog(url, name, width, height);
}

function IsDialog()
{
	return window.DialogObject != null
}

function CloseParentPage()
{
	GetCurrentDialog().Close();
}

function RefreshParentPage()
{
		var pwin = GetDialogParentWindow();
		if (pwin.GlobalBaseUrl == null)
		{
			GetDialogParentWindow().location.reload();
		}
		else
		{
			pwin.location.href = pwin.GlobalBaseUrl;	
		}
}

function NavigateParentPage(url)
{
    GetDialogParentWindow().location.href = url;
}

function NavigateRootPage(url)
{
    top.location.href = url;
}

function GetDialogParentWindow()
{
	if (window.SuggestBoxObject)
	{
		return window.SuggestBoxObject.ownerWindow.GetDialogParentWindow();
	}

	var d = GetCurrentDialog();
	if (d == null)
	{
		return null;
	}
	else
	{
		if (d.ownerDialog == null)
		{
			return d.parentWindow;
		}
		else
		{
			return d.ownerDialog.window
		}
	}
}

function GetParentElement(id)
{
	return GetDialogParentWindow().document.getElementById(id);
}

function SetParentInputValue(id, value)
{
    if (typeof(value) == 'undefined')
    {
				var elArray = document.getElementsByName(id);
				if (elArray.length==0)
				{
					el = document.getElementById(id);
				}
				else
				{
					if (elArray.length==1)
					{
						el = elArray[0];
					}
					else
					{

						var i; 
						for (var i = 0; i < elArray.length; i++) 
						{
							if (elArray[i].checked == true)
							{
								el = elArray[i];
								break;
							}
						}

					}
				}
        GetParentElement(id).value = el.value;
    }
    else
    {
    
        GetParentElement(id).value = value;
    }
}

function SetParentInnerHtml(id, value)
{
	GetParentElement(id).innerHTML = value;
}

/*---*/