/*
	navigation script
	12-10-2001
	Original:  Kevin Lynn Brown
	changes: Han
	sep		is the separator string; default "->"
	homeLevel	determines the first link in the navigation string
	   		default is "1" which means /www.fi.uu.nl/subsite_name/
	firstLinkText	is the text of the first link; the url is the default
	type		has only one value that makes sense: 'long'
	     		in this case the document name is also printed as the last link
	
*/


function navHelp (sep,homeLevel,firstLinkText,type)
{
	var path = "";
	var href = document.location.href;
	var s = href.split("/");
	var len = s.length-1;
	
	if ( sep == null || sep.replace(/ /g,"") == "" )
	{
		sep = " -> ";
	}
	
	if ( homeLevel == null || homeLevel.replace(/ /g,"") == "" )
	{
		homeLevel = 1;
	}
	else
	{
		// should first check on int here
		if ( homeLevel < 0 )
			homeLevel = 0;

	}
	
	homeLevel += 2;
	
	if ( homeLevel >= len )
		homeLevel = len - 1;
	
	if ( firstLinkText == null || firstLinkText.replace(/ /g,"") == "" )
	{
			firstLinkText = "url";
	}
	
	if ( type == null || type.replace(/ /g,"") == "" )
	{
		type = "default";
	}
	
	if ( homeLevel == len -1 && firstLinkText != "url" )
	{
		document.writeln('<span class="navHelp"><br /></span>'); 
		return;
	}

	for (var i=2;i<len;i++)
	{
		if ( i <= homeLevel && homeLevel != 2)
		{
			s[i] =s[i-1]+"/"+s[i];
			if ( i != homeLevel )
				continue;
		}
		
		target="_top"
			
		if ( i == homeLevel && firstLinkText != "url" )
		{
			refText = firstLinkText;
		}
		else
		{
			refText = s[i];
			if ( i != homeLevel )
			{
				target = "_self";
			}
		}

		path+="<a class=\"navHelp\" target=\"" + target + "\" href=\""+href.substring(0,href.indexOf(s[i])+s[i].length)+"/\">"+refText+"</a>";
		if ( i < len - 1 )
		{
			path += sep;
		}
	}

	if ( type == "long" )
	{
		path += sep+s[len];
	}
	var out = '<span class="navHelp">'+path+'</span>';
	document.writeln(out);
	//alert(out);
}

function writeCopyright ()
{
	var today=new Date();
	out=today.getYear();
	if ( out < 2000 )
		out += 1900;
	document.writeln('<div class="copyright">&copy; Freudenthal Institute for Science and Mathematics Education (FIsme) 1991-'+out+'</div>');
}

function writeThisYear()
{
	var today=new Date();
	out=today.getYear();
	if ( out < 2000 )
		out += 1900;
	document.write(out);
}


/* do a Google search; is called from a custom Form or a Form defined by googleSearchForm(3Ljs)
   first version author: Han */

function googleSearch ( queryInputTextElement, urlRestriction, targetWindow, siteRestriction )
{
	
	if ( siteRestriction == null || siteRestriction.replace(/ /g,"") == "" )
		siteRestriction = 'fi.uu.nl';


	siteRestriction = 'site:' + siteRestriction + ' ';
	
	if ( urlRestriction == null || urlRestriction.replace(/ /g,"") == "" )
		// use a space here for separation
		urlRestriction = " ";
	else
		urlRestriction = urlRestriction+ " ";
	
	if ( targetWindow == null || targetWindow.replace(/ /g,"") == "" )
		targetWindow="_blank";
	
	
	qstring = siteRestriction + urlRestriction + queryInputTextElement.value;
	url = "http://www.google.com/search?hl=nl&q="+qstring+"&btnG=Google+zoeken&lr=" ;

	window.open(url, targetWindow);
}

/* put a standard Google search Form in a doc; is used in the FrameMaker Web Template
   first version author: Han */

function googleSearchForm ( urlRestriction, buttonName, targetWindow, siteRestriction )
{
	// arguments passed to googleSearch(3Ljs) need to be quoted for the right syntaxis of
	// the onclick="googleSearch(...)" calling text that is written to the document
	
	if ( urlRestriction == null )
		urlRestriction = "''";
	else
		urlRestriction = "'"+urlRestriction+"'";
	
	if ( buttonName == null || buttonName.replace(/ /g,"") == "" )
		buttonName = "Zoek";
	
	if ( targetWindow == null || targetWindow.replace(/ /g,"") == "" )
		targetWindow="'_blank'"
	else
		targetWindow = "'"+targetWindow+"'";
		
	if ( siteRestriction == null )
		siteRestriction = "'fi.uu.nl'";
	else
		siteRestriction = "'"+siteRestriction+"'";

	document.writeln('<form name="standardGoogleSearch">');
	document.writeln('<input type="text" name="standardGoogleSearchQueryField" size="30" maxlength="70" value="">');
	document.writeln('<input type="button"  value="'+buttonName+'" onclick="googleSearch(standardGoogleSearchQueryField,'+urlRestriction+','+targetWindow+','+siteRestriction+')">');
	document.writeln('</form>');
}


/* create a new Browser Window with user control over all properties
   use it like: <a href="...."  onclick="return newWindow(this.href, .....);"> .... </a>
   first version author: Han */

function newWindow( url, windowBorderProperties, width, height, positionTop, positionLeft)
{
	DEFAULT_NO_PROPS='directories=no, location=no, menubar=no, status=no, toolbar=no';
	MINIMAL_PROPS = DEFAULT_NO_PROPS + ',scrollbars=no, resizable=no';
	SCROLL_PROPS = DEFAULT_NO_PROPS + ',scrollbars=yes, resizable=no';
	RESIZE_PROPS = DEFAULT_NO_PROPS + ',scrollbars=no, resizable=yes';
	SCROLL_RESIZE_PROPS=DEFAULT_NO_PROPS + ',scrollbars=yes, resizable=yes';
	ALL_YES_PROPS='scrollbars=yes, resizable=yes, directories=yes, location=yes, menubar=yes, status=yes, toolbar=yes';
	DEFAULT_WIDTH= '500';
	// other window targets do not work obviously
	TARGET = '_blank';
	
	// handle args and assign defaults
	
	if ( url == null || url.replace(/ /g,"") == "" )
		url='http://www.fi.uu.nl/intern/ict/development/web/javascript/reference.html';

	if ( windowBorderProperties == null )
		windowBorderProperties = 'default';
		
	if ( width == null || width.replace(/ /g,"") == "" )
		width = DEFAULT_WIDTH;
		
	if ( width > screen.width )
		width = screen.width;
		
	if ( height == null || height.replace(/ /g,"") == "" )
		height = width;
		
	if ( height > screen.height )
		height = screen.height;
		
	if ( positionTop == null )
		positionTop = 'center';

	if ( positionLeft == null )
		positionLeft = 'center';
		
	switch (windowBorderProperties) 
	{ 
	   case "minimal" : 
	      	winProps = MINIMAL_PROPS; 
	      	break; 
	   case "scroll" : 
	      	winProps = SCROLL_PROPS; 
	      	break; 
	   case "resize" : 
	      	winProps = RESIZE_PROPS; 
	      	break; 
	   case "default" :
	   	winProps = SCROLL_RESIZE_PROPS;
	      	break; 
	   case "full" :
	   	winProps = ALL_YES_PROPS;
	      	break; 
	   	
	   default:
	   	// it's a custom Window Property string; no checks on syntax are done here!
	      	winProps = windowBorderProperties; 
	}
	
	if ( positionTop == 'center' )
		positionTop = (screen.height - height) / 2;
	
	if ( positionLeft == 'center' )
		positionLeft = (screen.width - width) / 2;

	
	winProps = winProps	+ ',width=' + width + ',height=' + height
				+ ',left=' + positionLeft + ',top=' + positionTop;


	// note that TARGET has the value '_blank'; TARGET='_parent' does not give control on Window Props
	// some documentation (e.g. w3schools) does not imply this obvious behavior
	
	win = window.open(url, TARGET, winProps);
	
	if (parseInt(navigator.appVersion) >= 4)
		win.window.focus();
	return false

}


// newWindowPop is depricated; de naam deugt niet; newWindow betekent: in een ander Window
// daar hoeft Pop niet aan te worden toegevoegd
// is vervangen door newWindowLink (zie hierna)
//
// in de man Page stond: opent een nieuw Window; dat is onjuist!
// de functie _publiceert_ een link in het doc die zal worden geopend in
// in een nieuw Window; daarvoor wordt een call van newWindow (zie boven) gebruikt
// zie b.v ook het verschil tussen: GoogleSearch en GoogleSearchForm

function newWindowPop ( linkTxt, url, windowBorderProperties, width, height, positionTop, positionLeft )
	// note: property-parameters nog niet uitgewerkt in document.write, vnl voor gebruik samen met Framemaker javaScriptFunctionCall format
{		
		document.write('<a href=' +url+' onclick="return newWindow(this.href);">' +linkTxt+ '</a>');
}


function newWindowLink ( linkTxt, url, windowBorderProperties, width, height, positionTop, positionLeft )
	// note: property-parameters nog niet uitgewerkt in document.write, vnl voor gebruik samen met Framemaker javaScriptFunctionCall format
{		
		document.write('<a href=' +url+' onclick="return newWindow(this.href);">' +linkTxt+ '</a>');
}


// helper function

function fmReplaceSomeEntities(arg)
{
	arg = arg.replace(/&lt;/g,"<");
	arg = arg.replace(/&gt;/g,">");
	arg = arg.replace(/&rsquo;/g,"'");
	arg = arg.replace(/&quot;/g,'"');
	return arg;
}
	
// supports FrameMaker -insert-HtmlLine format
// writes the line in the doc

function fmInsertHtmlLine(arg)
{
	// the text is embedded bij Framaker in <div> ... </div>
	// the arg can contain a <div> that must be closed later ....
	// so do some closure and opening of generated div's
	//alert(arg);
	out='</div>' + fmReplaceSomeEntities(arg) + '<div>'
	document.write(out);
	//alert(out);
}

// supports FrameMaker platAcceptHtml format

function fmPlatAcceptHtml(arg)
{
	document.write("<p class='plat'>");
	document.write(fmReplaceSomeEntities(arg));
	document.write("</p>");

}

