function checkFeld(currFeld, laenge, nextFeld)
{
	if (currFeld.value.length == laenge)
	{
		if (nextFeld == "go"){
			document.forms[0].submit();
		}else{
			document.forms[0][nextFeld].focus();
		}
	}
}


function checkValidation()
{
    if (typeof(Page_ClientValidate) == "undefined") 
    {
        return true;
    }
    else
    {
        return Page_ClientValidate('');
    }
}

function openImage(image, path) {
	imageWindow = window.open("","image","width=400,height=300,resizable=no,scrollbars=no,status=0");

	with (imageWindow) {
		document.write('<html>\n');
		document.write('<head>\n');
		document.write('<title>' + image + '</title\n>');
		document.write('<meta http-equiv=\"imagetoolbar\" content=\"no\">\n');
		document.write('<style>\nhtml{overflow:hidden;}\nbody{overflow:hidden;}\n</style>\n');
		document.write('</head>\n');
		document.write('<body leftmargin=\"0\" topmargin=\"0\" marginwidth=\"0\" marginheight=\"0\"	scroll=\"no\" onload=\"opener.openImagePosition(window);\">\n')
		document.write('<a href=\"javascript:self.close()\">\n');
		document.write('<img src=\"' + path + image + '\" border=\"0\">\n');
		document.write('</body>\n');
		document.write('</html>');
		document.close();
	}
}

var currentLoadingPanel = null;
var currentUpdatedControl = null;

function ajaxDisableControls(loadingPanel, updatedPanel)
{
    currentLoadingPanel = RadAjaxNamespace.LoadingPanels[loadingPanel];

    currentUpdatedControl = updatedPanel;
    alert('start' + currentLoadingPanel);
}

function ajaxEnableControls()
{
    if (currentLoadingPanel != null)
    {
        alert('finished');
        currentLoadingPanel.Hide(currentUpdatedControl);
    }
    else
    {
        alert('not loaded');
    }
}

function bodyOnLoad(radAjaxManager)
{
    setTimeout(function() {
        window[radAjaxManager].AjaxRequest('InitialPageLoad');
    }, 200);
}

function openImagePosition(imageWindow) {
	if (imageWindow.innerWidth){
		iWidth = imageWindow.innerWidth;
		iHeight = imageWindow.innerHeight;
	}else{
		iWidth = imageWindow.document.body.clientWidth;
		iHeight = imageWindow.document.body.clientHeight;
	}

	//Firefox Korrektur
	if (iWidth > 400) iWidth = iWidth - (iWidth - 400);

	iWidth = imageWindow.document.images[0].width - iWidth;
	iHeight = imageWindow.document.images[0].height - iHeight;

	if (navigator.appName.toLowerCase() == 'microsoft internet explorer') {
	}else if (navigator.appName.toLowerCase() == 'netscape') {
// 		iWidth -= 15;
// 		iHeight -= 10;
	}else{
// 		alert(navigator.appName.toLowerCase());
//navigator.appVersion.substring(0,1) < "5")
	}

	imageWindow.resizeBy(iWidth, iHeight);


	//Fenster zentrieren
	posX = (screen.availWidth / 2) - (imageWindow.document.images[0].width / 2);
	posY = (screen.availHeight / 2) - (imageWindow.document.images[0].height / 2);
	
	imageWindow.moveTo(posX, posY);
}

function autoload()
{
    if( typeof(window.optimizeTabs) == "function" )
        optimizeTabs();
}

function autoresize()
{
    if( typeof(window.optimizeTabs) == "function" )
        optimizeTabs();
}

function optimizeEditor( editorclientid, firsttab )
{
    var height;
    var width;
    var posfooter = getTabPos('footer').top;
    var postab = getTabPos( editorclientid.Id ).top;

    height = posfooter - postab - 50;
    width = document.body.clientWidth * 0.95 - getTabPos(editorclientid.Id).left;
    
       
 
    editorclientid.SetSize( width, height );
    
    // Das wird benötigt, wenn der Editor auf dem ersten Tab sitzt
    if( firsttab == null )
        firsttab = true;
        
    if( firsttab == true )
    {
        setTimeout(
            function()
            {
                editorclientid.SetSize( width, height );
            }
            ,500);
    }
}


function optimizeTabHeight( tabclientid, subitems, lowestitems )
{
    // Bei iframes ist bei subitem der name-Parameter des iframes anzugeben
    var pageViewElement;
    var itemElement;
    var height;
    var lowestheight;
    var posfooter = getTabPos('footer').top;
    var postab = getTabPos(tabclientid.PageViews[0].ClientID).top;
    var n;
    var oldHeight = 0;


    
    if( document.getElementById( 'masteritem' ) != null )
    {    
        height = getLayerPosition( 'masteritem', "h" ) + getTabPos('masteritem' ).top;
        
        if( height > posfooter - 50 )
            return;
    }

    for( n = 0; n < tabclientid.PageViews.length; n ++ )
    {
        if( postab == 0 )
            postab = getTabPos(tabclientid.PageViews[n].ClientID).top;

            
        pageViewElement = document.getElementById(tabclientid.PageViews[n].ClientID);
        
        height = posfooter - postab - 50;
        
        if( document.getElementById( 'bottomitem' + n ) != null )
        {
            if( height + postab < getTabPos( 'bottomitem' + n ).top )
                height = getTabPos( 'bottomitem' + n ).top - postab;
        }

        if( height < oldHeight )
            height = oldHeight;
        
        oldHeight = height;

        if( pageViewElement != null )
            pageViewElement.style.height = height + "px";
        //            pageViewElement.style["min-height"] = height + "px";
    }
    
    if( subitems != null )
    {
        for( n = 0; n < subitems.length; n ++ )
        {
            itemElement = document.getElementById(subitems[n]);
        
            if( itemElement != null )
            {
                height = posfooter - getTabPos(subitems[n]).top - 70;
                lowestheight = getlowestheight( subitems[n], lowestitems );
                if( height > lowestheight ) height -= lowestheight;
            
                itemElement.style.height = height + "px";        
            }
        }
    }   
    
}

function getlowestheight( parentid, lowestitems )
{
    var parent_of_lowest;
    var pos;
    var itemElement;
    var height;
    
    height = 0;
    
    if( lowestitems != null )
    {
        for( n = 0; n < lowestitems.length; n ++ )
        {
            pos = lowestitems[n].indexOf( ':' );
            if( pos != -1 )
            {
                if( lowestitems[n].substring( 0, pos ) == parentid )
                {                
                    itemElement = document.getElementById( lowestitems[n].substring( pos+1 ) );
                    if( itemElement != null )
                        height += getLayerPosition(itemElement.id, "h" );
                 }
            }
        }
    }
    
    return height;
}

function getTabPos(el)
{
	var pos = {left:0, top:0};
	var o = document.getElementById(el);

	while(o)
	{
		pos.top += o.offsetTop;
		pos.left += o.offsetLeft;
		o = o.offsetParent;
	}

	return pos;
}

function getLayerPosition(id, pos) {
	var x;
	var y;
	var w;
	var h;

	if (document.all) {
		x = document.all[id].offsetLeft;
		y = document.all[id].offsetTop;
		w = document.all[id].scrollWidth;
		h = document.all[id].scrollHeight;
	}else if (document.layers) {
		x = document[id].left;
		y = document[id].top;
		w = document[id].clip.width;
		h = document[id].clip.height;
	}else{
		x = document.getElementById(id).style.left;
		y = document.getElementById(id).style.top;
		w = document.getElementById(id).offsetWidth;
		h = document.getElementById(id).offsetHeight;
	}

	switch (pos)
	{
		case "w":
			return (w);
			break;
		case "h":
			return (h);
			break;
		case "x":
			return x;
			break;
		case "y":
			return y;
			break;
	}
}

function openwindow( url, w, h, title )
{
   openw=window.open( url,title,
    "toolbar=no,directories=no,menubar=no,location=no,status=yes,resizable=yes,scrollbars=no,width=" + w + ",height=" + h);
   if(openw!=null)
   {
      if(openw.opener == null) 
      {
         openw.opener=self;
      }
   }
   return false;}

function openradwindow(url, w, h, title) {
    var ownd = window.radopen(url, title);
    ownd.SetSize(w, h);

    return ownd;
}

function getKeyCode(eve) {

    var evtobj = null;

    if (!eve)
        evtobj = window.event;
    else
        evtobj = eve;

    if (evtobj == null)
        return null;

    if (evtobj.keyCode)
        return evtobj.keyCode;
    else if (evtobj.which)
        return evtobj.which;
    else
        return null;
}


