// scripts to open popup windows for multimedia files, CSR reports, glossary and for general purposes (top function)

/*
This first function specifies the opening of a normal external window, prevously achieved by using the
target="_blank" attribute, now deprecated in XHTML 1.0 Strict.
*/
function externalLinks() {
 if (!document.getElementsByTagName) return; // doesn't work on this browser
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) { // loop through and find all anchor tags 
   var anchor = anchors[i];
   // below: check the a tag has an href attribute AND the new rel="external" attribute 
   if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") 
   {
	   anchor.target = "_blank"; // if so, set the target attribute here 
	   anchor.title = "External site; opens in new browser window" // less crucially you can set the title as well
   }
   // this is incidental but useful; if the url string contains ".pdf" it must be a link to a pdf so output a title attribute
   //href = anchor.getAttribute("href");
   //if (href.match(".pdf"))
   //{
   //	anchor.title = "Download as pdf";   
   //}
 }
}


function openWin(path, page) {
	var url = "/ukt" + path + page + ".jsp"
	window.open(url, 'Popup', 'scrollbars=yes,top=0,left=0,height=550,width=580,resizable=yes,screenx=no,screeny=no')
}

function openPopup(url) {
	window.open(url, 'Popup', 'scrollbars=yes,top=0,left=0,height=550,width=900,resizable=yes,screenx=no,screeny=no')
}

/* a more flexible method of the above, with more parameters for greater control of the window*/
function openWinFlex(path,width,height,top,left,ext) {
	
	if (!ext) {//if no extension specified make it .jsp by default
		var ext = '.jsp'
	}
	var url = "/ukt" + path + ext;

	window.open(url, 'Popup', 'scrollbars=yes,top=' + top + ',left=' + left +  ',width=' + width + ',height=' + height + ',resizable=yes,screenx=no,screeny=no,toolbar=yes')
	

}	
/* a fixed window, with no scrollbars and not resizable*/
function openWinFixed(path,width,height,top,left, ext) {
	
	if (!ext) {//if no extension specified make it .jsp by default
		var ext = '.jsp'
	}
	var url = "/ukt" + path + ext;
	
	window.open(url, 'Popup', 'scrollbars=no,top=' + top + ',left=' + left +  ',width=' + width + ',height=' + height + ',resizable=no,screenx=no,screeny=no,toolbar=no')
	

}	
function watchFiller(fillerName, directory) {
	var url = "/ukt/multimedia/" + directory + "/swf/" + fillerName + ".swf"
	window.open(url, 'Popup', 'scrollbars=yes,top=0,left=0,height=300,width=300,resizable=yes,screenx=no,screeny=no')

}
function hearAd(adName) {
	var url = "/ukt/multimedia/audio/" + adName + ".mp3"
	window.open(url, 'Popup', 'scrollbars=yes,top=0,left=0,height=150,width=450,resizable=yes,screenx=no,screeny=no')

}
function popupAudio(clip) {
		var path = "/ukt/multimedia/audio/container.jsp?clip=" + clip
		var title = "Audio"
		window.open(path, title, 'scrollbars=yes,address=yes,top=0,left=0,height=400,width=580,resizable=yes,screenx=no,screeny=no')

}

function openCSReport(centreID) {
		var url = "/ukt/statistics/centre-specific_reports/tables_by_centre/container.jsp?page=reports&id=" + centreID
		window.open(url, 'Popup', 'scrollbars=yes,top=0,left=0,height=650,width=900,resizable=yes,screenx=no,screeny=no')

}
function openGlos(term) {
	var urls = "/ukt/statistics/centre-specific_reports/tables_by_centre/container.jsp?page=glos#" + term
		window.open(urls, 'Popup', 'scrollbars=yes,top=0,left=0,height=200,width=550,resizable=yes,screenx=yes,screeny=no')

}

function popupCat(page,param) {
	var urlParam = param
	switch(urlParam) {
	case 'Leaflet':
		urlParam1 = "filter_criteria=Leaflet";
		break;
	case 'poster':
		urlParam1 = "filter_criteria=Poster";
		break;
	case 'promo':
		urlParam1 = "filter_criteria=Promotional+item";
		break;	
	case 'sticker':
		urlParam1 = "filter_criteria=Sticker";
		break;	
	case 'black':
		urlParam1 = "filter_criteria=Black";
		break;	
	case 'asian':
		urlParam1 = "filter_criteria=Asian";
		break;	
	default:
		urlParam1 = "filter_criteria=Poster";

	break;
	}
		urlParam2 = "sort_by=alpha_asc"
		var path = "/ukt/campaigns/get_involved/promo_catalogue/toolkit/toolkit_container.jsp?" + urlParam1 + "&" + urlParam2
		var title = "Catalogue"
		window.open(path, title, 'top=0,left=0,height=550,width=670,resizable=yes,scrollbars=yes,toolbar=yes,location=yes')
}
window.onload = externalLinks;  //call this function when the page loads 
