// *********************************************************************************************
// *********************************************************************************************
// **
// **	frame_it.js - Prevents pages being shown without a frame 
// **
// ** 	version : 	1.00
// ** 	date    : 	April 21, 2005
// **   prgrmmr : 	Ger Dik
// **
// *********************************************************************************************
// *********************************************************************************************

// = C O N S T A N T S  ========================================================================

DefaultFramepage  	= "http://www.te-les-koop.nl/index.html";
//DefaultFramepage  	= "index.html";
navWidth 			= 190;                   
minFramesWidth 		= 2*navWidth;					// minimum screenwidth for frames 
ContentFrameIdx 	= "mainFrame";					// Id of the content frame 
DefaultContent 		= "advertenties.php";			// initially shown inside the content frame

// =============================================================================================
var canUseFrames = false;       // see checkFramesURL()

// *********************************************************************************************
// *	OnFramePage
// *  	===========
// *
// * 	Are we on the frame page or not?? 
// *********************************************************************************************
function OnFramePage( AlternateFramePage )
{
	// determine the URL of the frame page
	if ((AlternateFramePage == "") || (AlternateFramePage == undefined))
	{
		UrlFrame = DefaultFramepage;
	}
	else
	{
		UrlFrame = AlternateFramePage;
	}
	// determine the URL of the page which is the actual parent at this moment
	UrlParent = parent.location.href;
  	// strip everything behind the question mark.
	if ( UrlParent.indexOf( '?' ) >= 0 )	
	{
		UrlParent = UrlParent.substring(0, UrlParent.indexOf( '?' ) );
	}
	// not equal; check for implicit pagenames
	if (UrlParent != UrlFrame)
	{
		FramePageName = UrlFrame.substring( UrlFrame.lastIndexOf('/') + 1, UrlFrame.length );
		if ((FramePageName == "index.html") || (FramePageName == "index.htm"))
		{
			UrlFrame = UrlFrame.substring( 0, UrlFrame.lastIndexOf('/')+1 );
		}
	}
	return (UrlParent == UrlFrame);
}
// *********************************************************************************************
// *	PutFrame
// *  	========
// *
// * 	Put a frame around the current page 
// *
// *	Parameters:
// *	- AlternateFramePage 		An alternate frames page can be specified if desired
// *
// *	- PagesFolder				Specify if the page to be shown resides in a different 
// *								(sub)folder than the frames page. 
// *								
// *
// *********************************************************************************************
function PutFrame( AlternateFramePage, PagesFolder )
{
	// read the current URL and the URL of the page	which is on top
	UrlThis = window.location.href;	
	UrlTop = top.location.href;
	
	// If these URLs are the same, it means that the current page is shown without a 
	// frame. Hence action must be taken to put a frame around the current page
	if (UrlThis == UrlTop )
	{
		// determine the URL of the frame page
		if ((AlternateFramePage == "") || (AlternateFramePage == undefined))
		{
			UrlFrame = DefaultFramepage;
		}
		else
		{
			UrlFrame = AlternateFramePage;
		}

		// if there is enough room for frames, take action
		if ( window.screen.availWidth >= minFramesWidth )
		{
			// extract the name of the current page current URL
			ShowPage = UrlThis.substring( UrlThis.lastIndexOf('/') + 1, UrlThis.length );
			//ShowPage = ShowPage.substring( ShowPage.lastIndexOf('?') + 1, ShowPage.length );  			 
			
			// javascript replace replaces only first occurrence 
	   		// which is exactly what we need: the first parameter
			// becomes the second, and needs an '&' in stead of a '?'
			ShowPage = ShowPage.replace("?","&");			
			
			if ((PagesFolder == "") || (PagesFolder == undefined))
			{
				NewPage = ShowPage;
			}
			else
			{
				NewPage = PagesFolder + "/" + ShowPage;
			}
			NewUrl = UrlFrame + "?" + NewPage;   
			window.location.href = NewUrl; 
		} // if enough room
    }  // if URL page  = URL top
} // PutFrame

// *********************************************************************************************
// *	AutoPage
// *  	========
// *
// * 	Analyse the URL and extract the content page name, which is the portion behind the 
// *	question mark.  Then show the content page inside the content frame.
// *	If there is no question mark, then show the default content.
// *
// *	Parameter:
// *	- AlternateDefContent 		An alternate name of the default content page
// *								can be specified if desired.
// *
// *********************************************************************************************
function AutoPage( AlternateDefContent )
{
	// WhereAmI();
	// determine the default page
	if ((AlternateDefContent == "") || (AlternateDefContent == undefined))
	{
		DefaultPage = DefaultContent;
	}
	else
	{
		DefaultPage = AlternateDefContent;
	}
	
	// read the current URL
	UrlWindow = window.location.href;
	if ( UrlWindow.indexOf( '?' ) > 0 )
    {
       ShowPage = UrlWindow.substring( UrlWindow.lastIndexOf('?') + 1, UrlWindow.length );  
	   // javascript replace replaces only first occurrence 
   	   // which is exactly what we need: the second parameter
 	   // becomes the first, and needs an '?' in stead of a '&'
	   ShowPage = ShowPage.replace("&","?");  
    }
	else
	{
		// standaardpagina
		ShowPage = DefaultPage;
	}
	//alert("De te tonen pagina is :\t"+ShowPage+"\nDe veronderstelde content frame heet:\t"+top.frames[ContentFrameIdx].name);
	//WhereAmI();
	top.frames[ContentFrameIdx].location = ShowPage;  
} // AutoPage

// *********************************************************************************************
// *	WhereAmI
// *  	========
// *
// * 	Test function
// *********************************************************************************************
function WhereAmI()
{
	UrlThis = window.location.href;
	UrlTop = top.location.href;
	UrlParent = parent.location.href;
	
	msg = "Deze pagina:\t"+UrlThis+"\n";
	msg = msg+"Top pagina:\t"+UrlTop+"\n";
	msg = msg+"Parent pag.:\t"+UrlParent+"\n\n";
	msg = msg+"Namen van de frames:\n";
	msg = msg+"1 :"+top.frames[1].name+"\n";
	msg = msg+"2 :"+top.frames[2].name+"\n";
	msg = msg+"3 :"+top.frames[3].name+"\n";
	msg = msg+"4 :"+top.frames[4].name+"\n";
	alert(msg);
}
// = EOF =======================================================================================
