function printPage(){
	document.getElementById('printStyleSheet').disabled = false;
	window.print();
}



function addListeners() {
  if (!document.getElementById)
    return;

  var all_ldcPhotosImgs = document.getElementsByName('ldcPhotosImg');
  	for (var i = 0; i < all_ldcPhotosImgs.length; i++) {
    		yellAddEvent(all_ldcPhotosImgs[i], 'mouseover', ldcEnlarge, false);
		yellAddEvent(all_ldcPhotosImgs[i], 'mouseout', ldcReduce, false);
		newSrc = all_ldcPhotosImgs[i].src.replace(/TMB/,"FLS");
		var image = new Array;
		image[i] = new Image(215,143);
		image[i].src = newSrc;
  }
  yellAddEvent(document.body, 'click', closePopUp, false);
}
function closePopUp(e){
	el = getEl(e);
	//alert(el.className+"\n"+ el.className.indexOf('noClose')+"\n"+el.parentNode.className.indexOf('noClose'))
	if( el.className =='' || (el.className.indexOf('noClose') == -1 && el.parentNode.className.indexOf('noClose') == -1)){
		//alert("el.tagName: "+el.tagName +"\nel.parentNode.className:"+el.parentNode.className);
		hideAllPopUps();
	}

}
function toggleMouseover(el){
	if(el.className.indexOf("mouseover") == -1){
		el.className += " mouseover";
	}else{
		el.className = el.className.replace(" mouseover", "");
	}

}
function init(){
	addListeners();
	//writePrintLink();
}
yellAddEvent(window, 'load',init, false);

function ldcEnlarge(e) {
	  var el;
	  if (window.event && window.event.srcElement)
	    el = window.event.srcElement;
	  if (e && e.target)
	    el = e.target;
	  if (!el)
    return;
	var link = el.parentNode;
	link.className="ldcPhotosLink2";
	el.className="ldcPhotosImg2";
	newSrc = el.src.replace(/TMB/,"FLS");
	el.src=newSrc;
}
function ldcReduce(e) {
	  var el;
  if (window.event && window.event.srcElement)
    el = window.event.srcElement;
  if (e && e.target)
    el = e.target;
  if (!el)
    return;
	var link = el.parentNode;
	link.className="ldcPhotosLink";
	el.className="ldcPhotosImg";
	newSrc = el.src.replace(/FLS/,"TMB");
	el.src=newSrc;
}
function searchMap_link_replace(){
	if(placesMMIsSupportedBrowser()) {
		var mapLinks = getElementsByClassName('searchMap_link');
		for(i=0;i<mapLinks.length;i++){
			mapLinks[i].href = mapLinks[i].href.replace(/ssm=1/,"ssm=0");
			mapLinks[i].href = mapLinks[i].href.replace(/ssm=&/,"ssm=0&");
		}
		var hiddenInputs = document.getElementsByName('ssm');
		for(i=0;i<hiddenInputs.length;i++){
			hiddenInputs[i].value="0";
		}
	}
}

function writePrintLink(){
	if (document.getElementById('writePrintLink')){
	 	var printLinkHTML = '<a href="javascript:;" onclick="printPage();return false" class="printLink">Print results</a>';
	 	document.getElementById('writePrintLink').innerHTML=printLinkHTML;
 	}
}


function bc_magic(){

	var fx = [];

	$$('ul.mover').each(function(item, index){
		var index = fx.length;
		fx[index] = new Fx.Slide(item,{
			duration: 300,
			transition: Fx.Transitions.Cubic.easeIn
		}).hide();
	});

	$$('a.toggle').each(function(item, index){
		item.addEvent('click', function(el){
			e = new Event(el);
			fx[index].toggle();
			e.stop();
			if(item.className=="toggle"){
				item.className = "toggle open";
			}else{
				item.className = "toggle";
			}
			item.blur();
		});
	});
}



// Popup image collection viewer

var currentImg = 1;
var imageSet=new Array();
var altSet = new Array();
var imageSetpath = '';
var blankImage = imageSetpath+'/img/imgViewer_tmp/blankImage.gif';
var t, u;

function dispImageSet(obj){
	
	while(obj.id.indexOf('advimgsmallid') != 0){
		obj = obj.offsetParent;
	}

	var pos = findPos(obj);
	var posRel = findPos(document.getElementById('expander'));
	
	document.getElementById('AjaxImgScr').style.top = pos[1]-posRel[1]+'px';
	document.getElementById('AjaxImgScr').style.left = pos[0]-posRel[0]-181+'px';

	document.getElementById('AjaxImgScr').style.display = 'block';
	document.getElementById('searchResultImgSet').src = blankImage;
	document.getElementById('searchResultImgSet').alt = "Loading gallery image";
	
	currentImg = 1;
	document.getElementById('searchResultImgSet').src = imageSetpath+imageSet[0];
	document.getElementById('searchResultImgSet').alt = altSet[0];
	
	document.getElementById('advimgbase_var1').innerHTML = currentImg;
	document.getElementById('advimgbase_var2').innerHTML = imageSet.length;
	if(imageSet.length==1){
		document.getElementById('AjaxImgScr_arrLeft').style.display = 'none';
		document.getElementById('AjaxImgScr_arrRight').style.display = 'none';
		document.getElementById('AjaxImgScr_Count').style.display = 'none';
	}
	else{
		document.getElementById('AjaxImgScr_arrLeft').style.display = 'block';
		document.getElementById('AjaxImgScr_arrRight').style.display = 'block';
		document.getElementById('AjaxImgScr_Count').style.display = 'block';
	}
}
function hideImageSet(obj){
	document.getElementById('AjaxImgScr').style.display = 'none';
	currentImg = 1;
	imageSet=new Array();
	altSet=new Array();
}

function dispImageSet_next(){
	clearTimeout(t);
	clearTimeout(u);
	document.getElementById('searchResultImgSet').src = blankImage;
	document.getElementById('searchResultImgSet').alt = "Loading gallery image";
	
	if(currentImg == imageSet.length){
		currentImg = 1;
	}else{
		currentImg = currentImg + 1;
	}
	document.getElementById('advimgbase_var1').innerHTML = currentImg;
	t = setTimeout("document.getElementById('searchResultImgSet').src = imageSetpath+imageSet[currentImg -1]",100);
	u = setTimeout("document.getElementById('searchResultImgSet').alt = altSet[currentImg -1]",100);
}
function dispImageSet_prev(){
	clearTimeout(t);
	clearTimeout(u);
	document.getElementById('searchResultImgSet').src = blankImage;
	document.getElementById('searchResultImgSet').alt = "Loading gallery image";
	if(currentImg == 1){
		currentImg = imageSet.length;
	}else{
		currentImg = currentImg - 1;
	}
	document.getElementById('advimgbase_var1').innerHTML = currentImg;
	t = setTimeout("document.getElementById('searchResultImgSet').src = imageSetpath+imageSet[currentImg -1]",100);
	u = setTimeout("document.getElementById('searchResultImgSet').alt = altSet[currentImg -1]",100);
}
function autoSubmit(formEl){
	while (formEl.tagName.toLowerCase() != "form") {
		formEl = formEl.parentNode;
	}
	formEl.onsubmit(); // Ensure onsubmit event is done before submitting the form...
	formEl.submit();
}
function toolsPrep(){
	for(i=0;i<gimme('.startPoint').length;i++){
		gimme('.startPoint')[i].value="e.g postcode";
		gimme('.startPoint')[i].onfocus = function(){
			this.value="";
		}
	}
	
	for(i=0;i<gimme('.autoSubmit').length;i++){
		gimme('.autoSubmit')[i].onchange = function(){
			if(this.selectedIndex!=0){
				changeClass(this);
				changeLoc(this);
				autoSubmit(this);
			}else{
				return false;
			}
		}
	}
}
function changeLoc(el){
	chosenOption = el.selectedIndex;
	chosenST = el.options[chosenOption].parentNode.label;
	if(chosenST=="Expand location"){
		for(i=0;i<gimme('.changeLocationST').length;i++){
			gimme('.changeLocationST')[i].value="expandedlocation";
		}
	}
	if(chosenST=="Related location" || chosenST=="Related locations"){
		for(i=0;i<gimme('.changeLocationST').length;i++){
			gimme('.changeLocationST')[i].value="relatedlocation";
		}
	}
	if(chosenST=="Narrow location"){
		for(i=0;i<gimme('.changeLocationST').length;i++){
			gimme('.changeLocationST')[i].value="narrowerlocation";
		}
	}				
}
function changeClass(el){
	chosenOption = el.selectedIndex;
	chosenST = el.options[chosenOption].parentNode.label;
	if(chosenST=="Similar searches" || chosenST=="Similar search"){
		for(i=0;i<gimme('.changeClassST').length;i++){
			gimme('.changeClassST')[i].value="relatedclassification";
		}
	}
	if(chosenST=="Narrow search"){
		for(i=0;i<gimme('.changeClassST').length;i++){
			gimme('.changeClassST')[i].value="refinedclassification";
		}		
	}
}