/*
Javascript functionality common to all files
If adding to this, please bear in mind progressive enhancement
- test for functionality before using it to avoid errors
*/
function bookmarkPage(){
//used by "bookmark page" link in page tools
if(window.sidebar){
//syntax for FF. 3rd empty string argument is required
window.sidebar.addPanel(document.title, location.href,'');
}else{
if(window.external){
//syntax for IE
window.external.AddFavorite(location.href,document.title);
}
}
}
function printPage(){
//used by "print page" link in page tools
window.print();
}
function findExitRamps(){
//identify any links with an exit ramp
aryExtLinks=getElementsByClassName(document,'external');
/*
possible HTML is:
*/
for(i=0;i0){
selectBox.options[i].selected=false;
}
//record setting of each option in array
selectBoxSelected[i]=selectBox.options[i].selected;
}
}
}
function toggleRelatedSelects(){
//checks whether "this site only" in site select box is selected
//if so, enables audience and area select boxes
//if not, disables them
var siteSelectBox=document.getElementById('rskey');
var areaSelectBox=getNamedElementId('select','sakey');
var audienceSelectBox=document.getElementById('saudkey');
if(siteSelectBox.options[0].selected==true){
if(areaSelectBox){
areaSelectBox.disabled=false;
}
if(audienceSelectBox){
audienceSelectBox.disabled=false;
}
}else{
if(areaSelectBox){
areaSelectBox.disabled=true;
}
if(audienceSelectBox){
audienceSelectBox.disabled=true;
}
}
return true;
}
function showHelp(){
//shows or hides the help popup for form field onclick
//popup also appears on hover - this is for keyboard users
//get a reference to the a tag which was clicked
el=this;
//switch off any other help popups
els=getElementsByClassName(document,'inhelplink');
already_set=false;
if(els){
for(var i=0,j=els.length; i0 && currentClass.indexOf(oldValue)!==-1){
//replace it
newClass=currentClass.replace(oldValue,newValue);
}else{
if(currentClass.indexOf(newValue)==-1){
//newValue not already in the className
//add it
newClass=currentClass+' '+newValue;
}else{
//newValue is already there so keep it as it is
newClass=currentClass;
}
}
}
setAttributeCrossBrowser(element,'class',newClass);
break;
default:
//this isn't finished - doesn't toggle at the moment, just overwrites
setAttributeCrossBrowser(element,attribute,newValue);
break;
}
}
function addPrototypeEffects(){
if(typeof Prototype !=='undefined'){
$$('.datepicker').each(function(el){
var picker = new Control.DatePicker(el, {datePicker: true,
timePicker: false,
locale: 'en_GB'
});
});
$$('.timepicker').each(function(el){
var picker = new Control.DatePicker(el, {datePicker: false,
timePicker: true,
use24hrs:true,
locale: 'en_GB'
});
});
$$('.blind').each(function(el){
el.observe('click',toggleBlinds);
});
/*something like this
new Effect.Move($('event_details'),{ x: 0, y: 0, mode: 'absolute' });
replace the X and Y values with Event.pointerX(event);
see http://www.prototypejs.org/api/event/pointerX
maybe combine with effect.appear - move it first then make it appear
try to make this generic - maybe a class on the link?
http://wiki.github.com/madrobby/scriptaculous/effect-appear
also have a think about absolutise in prototype
*/
}
}
/*
function addSWFObjects(){
if(typeof Prototype !=='undefined'){
$$('.swf_player').each(function(el){
swfobject.registerObject(el.id);
});
}
}
*/
function toggleBlinds(event){
var parentEl=event.element();
if(parentEl.id.startsWith('child')){
//we actually want to apply the effect to the named element
//in the format child_elementname
var childId=parentEl.id.split('_')[1];
var el=$(childId);
}
if(el){
Effect.toggle(el,'blind');
parentEl.toggleClassName('collapsed');
return false;
}
}
function attachEvents(){
//goes through the document
//finds elements which can have enhanced JS functionality
//adds that functionality, if supported
//find "print page" link
linkPrint=document.getElementById('print_page');
if(linkPrint){
if(window.print){
linkPrint.onclick=function(){printPage();};
}
}
//find "bookmark page" link
linkBookmark=document.getElementById('bookmark_page');
if(linkBookmark){
if(window.external || window.sidebar){
linkBookmark.onclick=function(){bookmarkPage();};
}
}
//necessary as more than one element has name sakey
sakey=getNamedElementId('select','sakey');
if(sakey){
sakey.onchange=function(){toggleSelection(sakey);};
}
//find site select on advanced search
rskey=document.getElementById('rskey');
if(rskey){
rskey.onchange=function(){toggleRelatedSelects();};
}
findExitRamps();
prepareHelpLinks();
//now call any additional functions which need to be executed onload
//these are defined in site, model or sub-model specific js files
//in an array called toCall
if(typeof(toCall)=='object'){
for(j=0;j