//-----------------------------------------------------------------------------
//  _JavaScript.js
//  Jan Vogels
//  2001-11-09
//  www.ato.wageningen-ur.nl
//-----------------------------------------------------------------------------

// Deze functie wijzigt de opgegeven variable in de querystring
function ChangeQueryString( StrQuery, StrOption )
{	
	StrArg		= StrOption.split( "=" );
	StrArguments	= StrQuery.split( "&" );
	i 	= 0;
	iFound	= -1;
	// Loop alle argumenten af	
	while ( i < StrArguments.length )
	{
		// Als het gezochte argument gevonden is wordt iFound gezet
		if ( StrArguments[ i ].search( StrArg[ 0 ] ) >= 0 )
		{
			iFound = i;
			break;
		}
		else
		{
			i += 1;	
			continue;
		}
	}
	
	// Als het gezochte argument gevonden is wordt de waarde gewijzigd
	// anders wordt de optie gewoon toegevoegd aan de string
	if ( iFound >= 0 )
	{
		StrArguments[ iFound ] = StrOption;
		StrQuery = StrArguments.join( "&" );
	}
	else
		StrQuery = StrOption + "&" + StrArguments.join( "&" );
	return StrQuery;
}


// Deze functie zorgt voor het actief maken van de rekenmachine
var NewWin = false;
function Calculator( ScrName, ScrWidth, ScrHeight )
{
	startDate	= new Date();
	yon		= "no";

	if ( !NewWin || NewWin.closed )
		NewWin = window.open( ScrName, startDate.getTime(),"toolbar=no,location=no,resizable="+yon+",status=no,scrollbars="+yon+",menubar=no,width="+ScrWidth+",height="+ScrHeight );
	else
		NewWin.focus();
}

function ATO_EditForm_HighLight( strTitle, strClass, strItem )
{
	var coll = document.all.item( strItem );
	if (coll != null)
		for (i=0; i<coll.length; i++)
			if ( coll.item(i).title == strTitle )
				coll.item(i).className = strClass;
}

// Deze functie zorgt voor het actief maken van het ventilatie uitlegschem
var VentilationWin = false;
function PopupVentilation( intDestination )
{
	iScrWidth   = 640;
    iScrHeight  = 480;
    startDate	= new Date();
	yon		= "no";

    if (isNaN( intDestination ) )
    {
        intDestination = 1;
    }

	if ( !VentilationWin || VentilationWin.closed )
		VentilationWin = window.open( "VentilationFold.asp?dst="+intDestination, startDate.getTime(),"toolbar=no,location=no,resizable="+yon+",status=no,scrollbars="+yon+",menubar=no,width="+iScrWidth+",height="+iScrHeight );
	else
		VentilationWin.focus();
}

// Deze functie zorgt voor het actief maken van het circulatie uitlegschem
var CirculationWin = false;
function PopupCirculation( intDestination )
{
	iScrWidth   = 640;
    iScrHeight  = 480;
    startDate	= new Date();
	yon		= "no";

    if (isNaN( intDestination ) )
    {
        intDestination = 1;
    }
	
    if ( !CirculationWin || CirculationWin.closed )
		CirculationWin = window.open( "CirculationFold.asp?dst="+intDestination, startDate.getTime(),"toolbar=no,location=no,resizable="+yon+",status=no,scrollbars="+yon+",menubar=no,width="+iScrWidth+",height="+iScrHeight );
	else
		CirculationWin.focus();
}

// Deze functie zorgt voor het actief maken van het TBar uitlegschem
var TBarWin = false;
function PopupTBar()
{
	iScrWidth   = 640;
    iScrHeight  = 480;
    startDate	= new Date();
	yon		= "no";

	if ( !TBarWin || TBarWin.closed )
		TBarWin = window.open( "TBarHeight.asp", startDate.getTime(),"toolbar=no,location=no,resizable="+yon+",status=no,scrollbars="+yon+",menubar=no,width="+iScrWidth+",height="+iScrHeight );
	else
		TBarWin.focus();
}

// Deze functie zorgt voor het actief maken van het TBar uitlegschem
var TBarWin = false;
function PopupTBarExplanation( intDestination )
{
	iScrWidth   = 640;
    iScrHeight  = 480;
    startDate	= new Date();
	yon		= "no";
    
    if (isNaN( intDestination ) )
    {
        intDestination = 1;
    }

    if ( !TBarWin || TBarWin.closed )
		TBarWin = window.open( "TBarExplanation.asp?dst="+intDestination, startDate.getTime(),"toolbar=no,location=no,resizable="+yon+",status=no,scrollbars="+yon+",menubar=no,width="+iScrWidth+",height="+iScrHeight );
	else
		TBarWin.focus();
}

// Deze functie zorgt voor het actief maken van het profile uitlegschem
var ProfileWin = false;
function PopupProfileExplanation()
{
	iScrWidth   = 640;
    iScrHeight  = 480;
    startDate	= new Date();
	yon		= "no";

	if ( !ProfileWin || ProfileWin.closed )
		ProfileWin = window.open( "ProfileExplanation.asp", startDate.getTime(),"toolbar=no,location=no,resizable="+yon+",status=no,scrollbars="+yon+",menubar=no,width="+iScrWidth+",height="+iScrHeight );
	else
		ProfileWin.focus();
}

// Deze functie zorgt voor het actief maken van het Extra uitlegschem
var TExtraWin = false;
function PopupExtra( intDestination )
{
	iScrWidth   = 640;
    iScrHeight  = 480;
    startDate	= new Date();
	yon		= "no";

    if (isNaN( intDestination ) )
    {
        intDestination = 1;
    }
	
    if ( !TExtraWin || TExtraWin.closed )
		TExtraWin = window.open( "ExtraExplanation.asp?dst="+intDestination, startDate.getTime(),"toolbar=no,location=no,resizable="+yon+",status=no,scrollbars="+yon+",menubar=no,width="+iScrWidth+",height="+iScrHeight );
	else
		TExtraWin.focus();
}

// Deze functie haalt alle velden van pForm op en slaat ze op in asResult
function GetAllFormValues( pForm, asResult )
{
	// Loop alle elementen af
	for ( i = 0; i < pForm.elements.length; i++ )
	{
		// hidden fields nemen we niet mee
		if ( pForm.elements( i ).type != "hidden" )
		{
			asResult[ i ] = pForm.elements( i ).value;
		}
		else
		{
			asResult[ i ] = "";
		}
	}
}

// Deze funtie vergelijkt de elementen InitVars en FinalVars en vraagt de gebruiker of
// de eventuele wijzigingen bewaard moeten worden
function CheckChangedValues( pForm, InitVars, FinalVars )
{
	var bChanged = new Boolean();

	for( i = 0; i < pForm.elements.length; i++ )
	{
		if ( InitVars[ i ] != FinalVars[ i ] )
		{
			bChanged = true;
		}
	}

	// return bChanged
	return bChanged;
}	

//-------------------------------------------------------------------------------------------
// Deze function zorgt ervoor dat het juiste aantal dagen per maand wordt weergegeven
//-------------------------------------------------------------------------------------------
function SetMonthDays( month, object )
{
	var MDays = new Array( 31,31,29,31,30,31,30,31,31,30,31,30,31);

	// empty selection list
	curSel = object.selectedIndex;

	numDays = object.length;
	for (i = 1; i < numDays; i++ )
	{
		object.remove(1);
	}

	// loop all days
	for ( i = 1; i <= MDays[ month.selectedIndex ]; i++ )
	{
		// create and append Opton element
		var oOption = document.createElement( "Option" );
		oOption.text = i;
		oOption.value = i;
		object.add( oOption );
	}

	// Set selection on no selection if out of array
	if ( curSel > MDays[ month.selectedIndex ] )
		object.selectedIndex = 0;
	else
		object.selectedIndex = curSel;
}


//-------------------------------------------------------------------------------------------
// Deze function geeft de resterende breedte van het scherm
//-------------------------------------------------------------------------------------------
function GetAvailableWidth( iReservedWidth )
{
    return window.screen.width - iRevervedWidth;
}

//-------------------------------------------------------------------------------------------
// Deze function geeft de resterende hoogte van het scherm
//-------------------------------------------------------------------------------------------
function GetAvailableHeight( iReservedHeight )
{
    return window.screen.height - iRevervedHeight;
}

// Deze function zorgt ervoor dat het juiste aantal dagen per maand wordt weergegeven
function GetMonthDays( iMonth, iYear )
{
	var dd = new Date( iYear, iMonth, 0);
	return dd.getDate();
}


