// last updated 17/05/2005 by Ra Khahn
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v3.0
  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); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// always name windows starting with 'NESTA'. see include.js for the reason
function urlWindow(url) {
	window.open(url,'NESTAurlwindow','scrollbars=yes,toolbar=yes,menubar=yes,location=yes,width=700,height=400, resizable=yes');
}

function printWindow(url) {
	window.open(url,'NESTAprintwindow','scrollbars=yes,toolbar=no,menubar=yes,location=no,width=700,height=400');
}

function feedbackWindow(url) {
	window.open(url,'NESTAfeedbackwindow','scrollbars=no,toolbar=no,location=no,width=500,height=350')
}
function videoWindow(url) {
	window.open(url,'NESTAvideowindow','scrollbars=no,toolbar=no,location=no,width=500,height=400')
}
function audioWindow(url) {
	window.open(url,'NESTAaudiowindow','scrollbars=no,toolbar=no,location=no,width=200,height=200')
}
function IdduWindow(url) {
	window.open(url,'NESTAidduwindow','scrollbars=no,toolbar=no,location=no,width=700,height=270')
}
function newVideoWindow(url) {
	window.open(url,'NESTAnewvideowindow','scrollbars=no,toolbar=no,location=no,width=635,height=439')
}

function slideWindow(url) {
	window.open(url,'NESTAslidewindow','scrollbars=no,toolbar=no,location=no,width=760,height=420')
}
function playWindow(url) {
	window.open(url,'NESTAplaywindow','scrollbars=no,toolbar=no,location=no,width=600,height=400')
}
function submitForm(formname) {
	theform = MM_findObj(formname, document);
	theform.submit();
}
function setFormElementValue(formname, elementname, val) {
	theform = MM_findObj(formname, document);
	theform.elements[elementname].value = val;
}
function setElementAndSubmit(formname, elementname, val) {
	theform = MM_findObj(formname, document);
	theform.elements[elementname].value = val;
	theform.submit();
}


//*******************************************************
//  Returns a string holding the full search 
// server root address. This should ALWAYS
// be used.
//
// eg, getSearchURL('/input.html') for the
// general search.
//*******************************************************
function getSearchURL(sEnd) {

	// check very specifically for dev - if not then LIVE (safer)
	if (document.domain.indexOf("nesta-cms") != -1) {
		// for dev
		sRoot =  "http://nesta-cms";
	}
	else {
		// for live
		 sRoot = "http://search.nesta.org.uk";
		// ip address for live if dns isnt working
		// sRoot = "http://217.158.13.24";
	}

	return sRoot + sEnd;
}

// use this in the 'onSubmit' handler of a form
function configureSearch(formname, actionurl) {
	theform = MM_findObj(formname, document);
	theform.action=getSearchURL(actionurl);
}

// use this in  a link that submits the named form e.g. <a href="javascript:performSearch('myform', '/index.html'');
function performSearch(formname, actionurl) {
	theform = MM_findObj(formname, document);
	theform.action=getSearchURL(actionurl);
	theform.submit();
}


//******************************************************************
//  These functions should be used for all general
//  (ie, header) site searches.
//******************************************************************
function configureGeneralSearch() {
	theform = MM_findObj('headsearch', document);
	theform.action=getSearchURL('/index.html');
}

function performGeneralSearch() {
	configureGeneralSearch();
	submitForm('headsearch');
}

//*****************************************************************
// here is a thing that lets you include static search strings into urls
//  the actionurl should include the query string in the form searchpage.html?qt=lalala&col=blahblah
//
//*****************************************************************
function searchLink(actionurl) {
	window.location.href = getSearchURL(actionurl);
}
