// Function to import other js files

function importFile(file) {
	var script_element = document.createElement('script');
	script_element.type = 'text/javascript';
	script_element.src = file;
	document.getElementsByTagName('head')[0].appendChild(script_element);
}

function currentPageInList(url_list) {
	for (var i = 0; i < url_list.length; i++) {
		if (url_list[i] == window.location) {
			return true;
		}
	}
	return false;
}

/* Create array of urls that point at the homepage */
var home_locations = new Array();
home_locations.push("http://www.vam.ac.uk/");
home_locations.push("http://www.vam.ac.uk/index.html");

/* if (currentPageInList(home_locations)) {
	importFile("/vam/js/va_survey.js");
} */

// Function for popup windows

function popup(URL,target,h,w) {
  return window.open(URL,target,"resizable=1,height="+h+",width="+w);
}

// Function for collections dropdown

function gocollect(selector)
{
  var selectedurl = selector.options[selector.selectedIndex].value;
  window.open(selectedurl,"_self");
}  

// Function to show/hide layers

function toggleBox(id, id1, id2, whichLink) {

    if (whichLink==0) {
        whichLink = 1;
    }else{
        whichLink = 0;
    }

	if (whichLink==1){
        document.getElementById(id).style.display="block";
        document.getElementById(id1).style.display="none";
	document.getElementById(id2).innerHTML="<a href=\"#\" onclick=\"toggleBox('" + id + "', '" + id1 + "', '" + id2 + "', " + whichLink + "); return false;\">Hide transcript</a>";
    }else{
        document.getElementById(id).style.display="none";
        document.getElementById(id1).style.display="block";
	document.getElementById(id2).innerHTML="<a href=\"#\" onclick=\"toggleBox('" + id + "', '" + id1 + "', '" + id2 + "', " + whichLink + "); return false;\">Show transcript</a>";
	}
}

// Function to display Email a Friend link

function getEmailAFriendLink() {
	var emailafriend_url = escape(window.location);
	var emailafriend_title = escape(document.title.replace("V&A - ",""));
	var emailafriend_link = "<li><a href=\"http://www.vam.ac.uk/vastatic/emailafriend/?url=" + emailafriend_url + "\&title=" + emailafriend_title + "\">Email this Page</a>\ | </li>";
	document.write(emailafriend_link);
}

// Function to clear out default placeholder messages from form inputs

function clearDefault(defaultMsg, control) {
	if (control.value == defaultMsg)
		control.value = '';
}

// Function to display dates for events newsletter

function event_newsletter_dates() {
	var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
	var start = new Date();
	var end = new Date(start.getFullYear(), start.getMonth() + 2, start.getDate(), 0, 0, 0);

	document.write('<div class="newsletter_dates">');
	//document.write('1 February - 1 March 2006');
	document.write(start.getDate() + ' ' + months[start.getMonth()] + ' ');
	if (start.getFullYear() != end.getFullYear()) { document.write(start.getFullYear() + ' '); }
	document.write(' - ' + end.getDate() + ' ' + months[end.getMonth()] + ' ' + end.getFullYear());
	document.write('</div>');
}

// Old code for backwards compatibility

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) { //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_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];}
}

