// Version 1.0

function IsMS()
{
	if(document.all ) 
	{
		return 1;
	}
}


function checkDel() { //v3.0

    Check = confirm("Wollen Sie wirklich löschen?");

    return Check;
}

function doPopup ( szURL, height )
{
    var x = ( screen.availWidth - 520 ) / 2;
    var y = ( screen.availHeight - height ) / 2;
    window.open( szURL,'','toolbar=no,left=' + x + ',top=' + y + ', scrollbars=yes, status=no, resizable=yes, width=520, height=' + height);
    return false;
}

function popupWindow ( szURL, width, height )
{
    var x = ( screen.availWidth - width ) / 2;
    var y = ( screen.availHeight - height ) / 2;
    window.open( szURL,'','toolbar=no,left=' + x + ',top=' + y + ', scrollbars=yes, status=no, resizable = yes, width=' + width + ', height=' + height );
    return false;
}

function popupWindowNoScroll ( szURL, width, height )
{
    var x = ( screen.availWidth - width ) / 2;
    var y = ( screen.availHeight - height ) / 2;
    window.open( szURL,'','toolbar=no,left=' + x + ',top=' + y + ', scrollbars=no, status=no, resizable = yes, width=' + width + ', height=' + height );
    return false;
}
function popupEditWindow ( szURL )
{
	var width = 800;
	var height = 500;
    var x = ( screen.availWidth - width ) / 2;
    var y = ( screen.availHeight - height ) / 2;
    window.open( szURL,'','toolbar=no,left=' + x + ',top=' + y + ', scrollbars=no, status=no, toolbar=no, resizable = no, width=' + width + ', height=' + height );
    return false;
}

function popupEditWindowScroll ( szURL )
{
	var width = 800;
	var height = 500;
    var x = ( screen.availWidth - width ) / 2;
    var y = ( screen.availHeight - height ) / 2;
    window.open( szURL,'','toolbar=no,left=' + x + ',top=' + y + ', scrollbars=yes, status=no, toolbar=no, resizable = no, width=' + width + ', height=' + height );
    return false;
}

function MoveToCard ( nNr )
{
    document.adminform._gotourl.value=ahURL [ nNr ];
    document.adminform.submit();
}

function DeleteReference ( szProperty )
{
    if ( confirm ( 'Sind Sie sicher, dass Sie diesen Eintrag entfernen möchten?' ) )
    {
    
        nItem = eval ( 'document.adminform.' + szProperty + '.value' );

        document.adminform._deletereference_item.value=szProperty;
        document.adminform._deletereference_value.value=nItem;

        document.adminform.submit();
    }
}

function NewReference ( szURL, width, height)
{
    popupEditWindow ( szURL );
    document.adminform.noclose.value="1";
    document.adminform._refresh.value="1";

    document.adminform.submit();    
    return false;
}

function EditReference ( szProperty, szURL, width, height )
{
    nItem = eval ( 'document.adminform.' + szProperty + '.value' );
    szURL += "?id=" + nItem;
    popupEditWindow( szURL );
    
    document.adminform.noclose.value="1";
    document.adminform._refresh.value="1";
    document.adminform.submit();    
    return false;
}

function NewSublistItem ( szURL, nParentItem, width, height)
{
    szURL += "?parentid=" + nParentItem;
    popupEditWindow( szURL );
    document.adminform.noclose.value="1";
    document.adminform._refresh.value="1";

    document.adminform.submit();
    return false;
}

function EditSublistItem ( nItem, szURL, nParentItem, width, height)
{
    szURL += "?parentid=" + nParentItem + "&id=" + nItem;
   
    popupEditWindow( szURL );
    return false;
}

function DeleteSublistItem ( nItem )
{
    if ( confirm ( 'Sind Sie sicher, dass Sie diesen Eintrag entfernen möchten?' ) )
    {   
        document.adminform._deletesublist_item.value=nItem;
        document.adminform.noclose.value="1";
    
        document.adminform.submit();
    }
}

function PreviewGalleryImage ( nItem )
{
    document.adminform._previewgalleryimage.value=nItem;
    
    document.adminform.noclose.value="1";
    
    document.adminform.submit();
}
   
function DeleteGalleryImage ( nItem )
{
    if ( confirm ( 'Send Sie sicher, dass Sie dieses Bild entfernen möchten?' ) )
    {
        document.adminform._deletegalleryimage.value=nItem;
    
        document.adminform.noclose.value="1";
    
        document.adminform.submit();
    }
}

function SelectFolderSelectItem ( szProperty, nItem )
{
    eval ( 'document.adminform.' + szProperty + '.value = nItem' );
    document.adminform.noclose.value="1";
    document.adminform.submit();
}
      
function EditMultipleReference ( szUrl, nItem, nWidth, nHeight )
{
    szUrl += "?id=" + nItem;
    
    popupEditWindow ( szUrl );
    
}

// Reloads list window and restores the current scrollposition
function ReloadListWindow()
{
    var aoScrollPosition = GetScrollPosition();
    
    var nScrollY = aoScrollPosition [ "y" ];
    
    var szCurrentUrl = document.URL;
    
    var nRemarkPos = -1;
    
    if ( ( nRemarkPos = szCurrentUrl.indexOf ( "#" ) ) != -1 )
    {
    	szCurrentUrl = szCurrentUrl.substring ( 0, nRemarkPos );
    }
    
    // Strip scrollpositiony, if it exists
    var nParaPos = -1;
    if ( ( nParaPos = szCurrentUrl.indexOf ( "scrollpositiony" ) ) != -1 )
    {
    	szCurrentUrl = szCurrentUrl.substring ( 0, nParaPos - 1 );
    }
    
    var szUrlAdd = "scrollpositiony=" + nScrollY;
    
    if ( szCurrentUrl.indexOf ( '?' ) == -1 )
    {
    	szCurrentUrl += "?" + szUrlAdd;
    }
    else
    {
    	szCurrentUrl += "&" + szUrlAdd;
    }
    
    document.location.href = szCurrentUrl;
}

// This function has to be recalled, after the ReloadListWindow has been executed
// It sets the scrollposition by the GET-parameter scrollpositiony.
// It is important that this function will be called after all data has been sent
function ListWindowReloaded()
{

    var szCurrentUrl = document.URL;
    
    // Strip scrollpositiony, if it exists
    var nParaPos = -1;
    if ( ( nParaPos = szCurrentUrl.indexOf ( "scrollpositiony" ) ) != -1 )
    {
    	var szScrollY = szCurrentUrl.substring ( nParaPos + 16 );
    	
    	window.scrollTo ( 0, szScrollY );
    }
}

// Gets currentscrollposition
function GetScrollPosition()
{
    var docEl = (
	 typeof document.compatMode != "undefined" && 
	 document.compatMode        != "BackCompat"
	)? "documentElement" : "body";

    var aoReturn = new Array();

    if (window.pageXOffset)
    {
	aoReturn [ "x" ] = window.pageXOffset;
    }
    else
    {   
	aoReturn [ "x" ] = document [docEl].scrollLeft;
    }

    if (window.pageYOffset)
    {
	aoReturn [ "y" ] = window.pageYOffset;
    }
    else
    {  
	aoReturn [ "y" ] = document [docEl].scrollTop;
    }

    return aoReturn;
}


function popupCloseAndSubmitOpener()
{
    window.opener.document.adminform.noclose.value="1";
    window.opener.document.adminform.submit();
    window.close();
}

var nMouseX = 0;
var nMouseY = 0;

function OnMouseMove ( e )
{
	if ( IsMS() )
	{
		nMouseX = window.event.x;
		nMouseY = window.event.y;	
	}
	else
	{
		
		nMouseX = e.pageX;
		nMouseY = e.pageY;
	}
}

document.onmousemove = OnMouseMove;


function CloseAdminInformation()
{
	getElem ( "id", "admininfo", "" ).style.visibility = "hidden";
	
	
	if ( IsMS() )
	{
		for (var i=0; i<document.all.length; i++) 
		{
			o = document.all(i)
			if (o.type == 'select-one' || o.type == 'select-multiple') 
			{	  
				if (o.style) o.style.visibility = 'visible';
			}
		}
	}
	
}

var nClipWidth;
var nClipHeight;
var nAdminInfoWidth; 
var nAdminInfoHeight;


function ShowAdminInformation( nWidth, nHeight, szTitle, szContent )
{
	setCont ( "id", "admininfotitle", "", szTitle );
	setCont ( "id", "admininfocontent", "", szContent );
	
	var nPosX = nMouseX + 10;
	var nPosY = nMouseY;
	
	if ( ( nPosY + nHeight ) > 450 )
	{
		nPosY = 450 - nHeight;
	}
	
	var AdminInfo = document.getElementById( "admininfo" );
	AdminInfo.style.width = nWidth + "px";
	AdminInfo.style.height = nHeight + "px";
	AdminInfo.style.left = nPosX + "px";
	AdminInfo.style.top = nPosY + "px";
	AdminInfo.style.visibility = "visible";
	
	if ( IsMS() )
	{
		for (var i=0; i<document.all.length; i++) 
		{
			o = document.all(i)
			if (o.type == 'select-one' || o.type == 'select-multiple') 
			{	  
				if (o.style) o.style.visibility = 'hidden';
			}
		}
	}
	
}


function UnclipAdminInformation()
{
	nClipWidth += 25;
	nClipHeight += 25;
	
	if ( nClipWidth >= nAdminInfoWidth )
	{
		nClipWidth = nAdminInfoWidth;
	}
	
	if ( nClipHeight >= nAdminInfoHeight )
	{
		nClipHeight = nAdminInfoHeight;
	}
	
	var AdminInfo = document.getElementById( "admininfo" );
	AdminInfo.style.clip = "rect ( 0px " + nClipWidth + "px " + nClipHeight + "px 0px )";
	
	if ( nClipWidth != nAdminInfoWidth || nClipHeight != nAdminInfoHeight )
	{
		window.setTimeout ( "UnclipAdminInformation()", 10 );
	}
}


function DeleteCollectionImage ( szImage )
{
    if ( confirm ( 'Send Sie sicher, dass Sie dieses Bild entfernen möchten?' ) )
    {
        document.adminform._deletecollectionimage.value=szImage;
    
        document.adminform.noclose.value="1";
    
        document.adminform.submit();
    }
}



function PreviewCollectionImage ( szImage )
{
    document.adminform._previewcollectionimage.value = szImage;
    
    document.adminform.noclose.value="1";
    
    document.adminform.submit();
}
