
function addToSearch(b,t){	//Add a new term onto the current search term
	oldSearch = document.searchscran.search_term.value;
	newSearch = oldSearch + " " + b + " " + t;
	document.searchscran.search_term.value = newSearch;
}


function openNewWindow(URLtoOpen, windowName, windowFeatures) {
	newWindow=window.open(URLtoOpen, windowName, windowFeatures); 
}

function selectStar(val){
	if (val ==1){	
		document.one.src = "/images/rating/full.gif"
		document.two.src = "/images/rating/blank.gif"
		document.three.src = "/images/rating/blank.gif"
		document.four.src = "/images/rating/blank.gif"
		document.five.src = "/images/rating/blank.gif"
	}
	if (val ==2){	
		document.one.src = "/images/rating/full.gif"
		document.two.src = "/images/rating/full.gif"
		document.three.src = "/images/rating/blank.gif"
		document.four.src = "/images/rating/blank.gif"
		document.five.src = "/images/rating/blank.gif"
	}
	if (val ==3){	
		document.one.src = "/images/rating/full.gif"
		document.two.src = "/images/rating/full.gif"
		document.three.src = "/images/rating/full.gif"
		document.four.src = "/images/rating/blank.gif"
		document.five.src = "/images/rating/blank.gif"
	}
	if (val ==4){	
		document.one.src = "/images/rating/full.gif"
		document.two.src = "/images/rating/full.gif"
		document.three.src = "/images/rating/full.gif"
		document.four.src = "/images/rating/full.gif"
		document.five.src = "/images/rating/blank.gif"
	}
	if (val ==5){	
		document.one.src = "/images/rating/full.gif"
		document.two.src = "/images/rating/full.gif"
		document.three.src = "/images/rating/full.gif"
		document.four.src = "/images/rating/full.gif"
		document.five.src = "/images/rating/full.gif"
	}
}

function selectStarOff(){
	document.one.src = "/images/rating/blank.gif"
	document.two.src = "/images/rating/blank.gif"
	document.three.src = "/images/rating/blank.gif"
	document.four.src = "/images/rating/blank.gif"
	document.five.src = "/images/rating/blank.gif"
}

//Macromedia function. why reinvent the wheel.

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
	document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

//used to create a search query from the 3 values entered in the full search page.
function doQSearch(){
	var searchTerm ="";
	searchTerm = document.ignoreForm.query1.value;
	if (document.ignoreForm.query2.value != "") {
		searchTerm = searchTerm+" "+document.ignoreForm.bool1.value+" "+document.ignoreForm.query2.value;
	}
	if (document.ignoreForm.query3.value != "") {
		searchTerm = searchTerm+" "+document.ignoreForm.bool2.value+" "+document.ignoreForm.query3.value;
	}
	document.frmQuick.$$.value = searchTerm;
	document.frmQuick.submit();
}

//	######################################################
//  The bunch of functions below are taken from scran_scripts_display.js
//  They allow the use of js code in the learning_materials section
//	dialogs section ****************    
//	set global variables ***********

var dlgWindow, dlgArgs, dlgWidth, dlgHeight, dlgLeft, dlgTop, dlgScrolls, dlgResize ;

var dlgTools   =  '0' ;
var dlgMenus   =  '0' ;
var dlgLocs    =  '0' ;
var dlgStatus  =  '0' ;
var whichDlg   =  '' ;

var screenAvailWidth  =  parseInt(screen.availWidth)  ;
var screenAvailHeight =  parseInt(screen.availHeight) ;
var screenWidth  =  parseInt(screen.width)  ;
var screenHeight =  parseInt(screen.height) ;



//	sets dialog features
function dlgFeatures(dlgId) {
	switch (dlgId) {
		case 'loginDlg'		:  ((dlgWidth =  320)  &&  (dlgHeight =  140)  &&  (dlgScrolls =  '0')	&&  (dlgResize='no')) ;  break ;
		case 'helpDlg'		:  ((dlgWidth =  540)  &&  (dlgHeight =  460)  &&  (dlgScrolls =  '1')	&&  (dlgResize='no')) ;  break ;
		case 'nonStrdDlg'	:  ((dlgWidth =  540)  &&  (dlgHeight =  460)  &&  (dlgScrolls =  '1')	&&  (dlgResize='yes')) ;  break ;
		case 'standardDlg'	:  ((dlgWidth =  540)  &&  (dlgHeight =  460)  &&  (dlgScrolls =  '1')	&&  (dlgResize='yes')) ;  break ;
		case 'controlDlg'	:  ((dlgWidth =  445)  &&  (dlgHeight =  460)  &&  (dlgScrolls =  '1')	&&  (dlgResize='yes')) ;  break ;
		case 'albumDlg'		:  ((dlgWidth =  600)  &&  (dlgHeight =  400)  &&  (dlgScrolls =  '1')	&&  (dlgResize='yes')) ;  break ;
		case 'roymapDlg'	:  ((dlgWidth =  600)  &&  (dlgHeight =  400)  &&  (dlgScrolls =  '1')	&&  (dlgResize='yes')) ;  break ;
		}
	
		return dlgWidth ;
		return dlgHeight ;
		return dlgScrolls ;
		return dlgResize ;
}


//	positions dialogs
function dlgPos(dlgWidth,dlgHeight) {
	dlgLeft =  Math.floor((screenAvailWidth  - dlgWidth)  / 2) ;
	dlgTop  =  Math.floor((screenAvailHeight - dlgHeight) / 2) ;
	
	return dlgLeft ;
	return dlgTop ;
}    


//	creates dialog and extra windows for website       
function dlgCreate(dlgId,dlgUrl) {
	dlgFeatures(dlgId) ;
	dlgPos(dlgWidth,dlgHeight,dlgLeft,dlgTop) ;
  
	dlgArgs =  ('width=' +dlgWidth+ ',height=' +dlgHeight+ ',left=' +dlgLeft+ ',top=' +dlgTop+ ',scrollbars=' +dlgScrolls+ ',toolbar=' +dlgTools+ ',menubar=' +dlgMenus+ ',location=' +dlgLocs+ ',status=' +dlgStatus+ ',resizable=' +dlgResize) ;          
  
	dlgWindow =  window.open(dlgUrl,dlgId,dlgArgs) ;     
	dlgWindow.focus() ;
}


function dlgClose() {
	if (dlgWindow) dlgWindow.close() ;	
}


function dlgRem() {
	if (window.dlgWindow && window.dlgWindow.open && !window.dlgWindow.closed)  window.dlgWindow.opener = null ;
}
//	-----------------------------------------
// the next three functions are taken from /utils/dhtml/js-code/scran_scripts_display.js

function getDBLink(strWeb,dbRecVal,dbRecType,winTarget) {
	objToStr(strWeb,dbRecVal,dbRecType)
	callDBQuery(dbLinkStr,winTarget) ;
}

// modified function to suit SCRAN2004
function objToStr(strWeb,dbRecVal,dbRecType) {
	var dbOpenStr	= '_IXDB_=meta&_IXFPFX_=t&submit-button=SUMMARY&%24%24=';

	switch (dbRecType)
	{
		case 'normal'		:	(typeStr = '+in+usi')				;	break ;
		case 'pathfinder'	:	(typeStr = '')					;	break ;
		case 'project'		:	(typeStr = '+in+project')			;	break ;
		case 'resources'	:	(typeStr = '+index+resource_pack_index')	;	break ;
		case 'resource'		:	(typeStr = '+index+resource_pack_index')	;	break ;
		case 'teaching'		:	(typeStr = '+index+resource_pack_index')	;	break ;
	}
	
	dbLinkStr = '/database/record.php?' + dbOpenStr + dbRecVal + typeStr;	
}

function callDBQuery(dbLinkStr,winTarget) {
	if (winTarget == 'parent') opener.location.href = dbLinkStr ;
	else if (winTarget == 'self') window.location.href = dbLinkStr ;
	else if (winTarget == 'child')
	{
		window.open(dbLinkStr,'childWin','') ;
		alert('Opening new window. \n\nOne moment, please ...') ;
		window.close() ;
	}
}
//	-----------------------------------------

// the 3 functions below are for checking form fields (caption comp. form)
function validRequired(formField,fieldLabel) {
	var result = true;
	
	if (formField.value == "") {
		alert('Please enter a value for the "' + fieldLabel +'" field.');
		formField.focus();
		result = false;
	}
	
	return result;
}

function validEmail(formField,fieldLabel,required) {
	var result = true;
	
	if (required && !validRequired(formField,fieldLabel)) {
		result = false;
	}
	
	if ( !required && formField.value == "") {
		return true;
	} else {
		if (result && ((formField.value.length < 3) || !isEmailAddr(formField.value)) )	{
			alert("Please enter a complete email address in the form: yourname@yourdomain.com");
			formField.focus();
			result = false;
		}
	}
	return result;

}

function validateCaptionForm(theForm) {
	// Customize the form fields to check
	if (!validRequired(theForm.caption,"caption"))	return false;		
	if (!validRequired(theForm.name,"name"))		return false;
	if (!validRequired(theForm.email,"e-mail"))		return false;	
	if (!validEmail(theForm.email,"email",false))	return false;
	
	return true;
}

function gotoURL(URL,item) {
	if (confirm('This '+item+' will be removed!\nAre you sure?')) {
		window.location=URL;
	}
}
