// JavaScript Document
var isFlashInstalled=false;
noautoinstall = "";
if(navigator.appName == "Microsoft Internet Explorer" && 
                (navigator.appVersion.indexOf("Mac") != -1 || 
                 navigator.appVersion.indexOf("3.1") != -1)){
                        noautoinstall = "true";
        }

if (navigator.appName == "Microsoft Internet Explorer" && noautoinstall != "true"){isFlashInstalled=true;}
		
else if(navigator.plugins)
        {
                if(navigator.plugins["Shockwave Flash"] || navigator.plugins["Shockwave Flash 2.0"])
                {isFlashInstalled=true;	
								
				}
          }
		  
//end flash detection		  

 function swapflash(movieName,container,width,height,flashid,staticimage){
		var newCode='';
        var flashCode='';
        var flashContainer='';
         //if(isFlashInstalled&&activestyle=="regular"){
         flashContainer=document.getElementById(container);
		 if(isFlashInstalled){
						movieName="flash/header_2.swf";
                       
                        //customisation
                        //flashContainer.style.position="relative";        
                        //flashContainer.style.backgroundImage="";
                        ///////////////
                        flashCode= "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" " ;
                        flashCode=flashCode + "codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" ";
                        flashCode=flashCode + "width=\"" + width + "\" height=\""+height+"\" >\n ";
                        flashCode=flashCode + "  <param name=\"movie\" value=\" " + movieName + " \">\n";
                        flashCode=flashCode + "        <PARAM NAME=\"wmode\" VALUE=\"transparent\" >\n";
                        flashCode=flashCode + "  <embed src=\""+ movieName + "\" quality=\"high\" wmode=transparent pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\""+width+"\" height=\""+height+"\">\n ";
                        flashCode=flashCode + "  </embed>\n";
                        flashCode=flashCode + "</object>\n";
                        
						//alert(flashContainer.innerHTML);
                        }						
		//newCode=flashCode+flashContainer.innerHTML;
		//alert(flashCode);
        flashContainer.innerHTML="<div id=\"flashmovie\">"+flashCode+"</div>";
}


function insertmailto(){
	swap=document.getElementById('emailus');
	//alert(swap.innerHTML);
	swap.innerHTML='<a href="mailto:david.peel@leeds.gov.uk" title="email us" >email us</a>';

	swap=document.getElementById('emailuslist');
	//alert(swap.innerHTML);
	swap.innerHTML='<a href="mailto:david.peel@leeds.gov.uk" title="email us" >Sign up for our newsletter</a>';
}


function makeheadergraphic(){
	grheader=document.getElementById('header');
	//alert(grheader.innerHTML);
	grheader.innerHTML='<div id="graphicalheader" ></div>' + grheader.innerHTML +'';
}

function imgPopup(url,alt){
        var openIpix='';
        var closeIpix='';
        var isIpix=false;
        urlExtension=url.split(".");
        if(urlExtension[urlExtension.length-1]=='ipx'){isIpix=true;}
        //else{alert('not an ipix, must be an image');}
                                        var imgPopup=window.open('','imgPopup','height=50,width=50,toolbar=no,scrollbars=no,resizable=yes,menubar=no,status=no,directories=no,location=no,50,50');
                                        imgPopup.document.open();
                                        imgPopup.document.writeln('<html><head><title>image</title> \n <style type="text/css"> \n a{color:#3f3479;} p#caption{background-color:#eeeeee;text-align: left;padding-left: 10px;padding-right: 10px;}  \n body {font-family: Tahoma, Arial, Helvetica, sans-serif;text-align: center;} \n p {font-size: 70%;margin-top: 0px;padding-top: 0.5em;padding-bottom: 1em;} \n img {display: block; margin-right: auto; margin-left: auto;} \n  p.close {text-align: center; margin-bottom: 0px;        width: 9em;        float: right;        color: #FFFFFF;           padding: 3px;        font-weight: normal;}  \n </style> \n </head> \n <body>');
                                                                               imgPopup.document.writeln('<img src="' + url + '" alt="' + alt + '" id="lrgimage" />');
                                                                               imgPopup.document.writeln(' \n<p class="close"><a href="javascript:window.close();">Close Window</a></p> \n </body> \n </html>');
                                                                               imgPopup.document.title=alt;
                                                                               var bigImage=imgPopup.document.getElementById('lrgimage');
                                        var captiontxt=imgPopup.document.getElementById('caption');
                                                                                //alert(bigImage.width);
                                        //captiontxt.style.color='#333333';
                                        //captiontxt.style.fontsize='70%';
                                        //1st resize for shitty explorer
                                                var newwidth=bigImage.width+60;
                                                if(!newwidth){newwidth=490;}
                                                var newheight=imgPopup.document.body.scrollHeight+40;
                                                imgPopup.resizeTo(newwidth,newheight);
                                                imgPopup.window.focus;
                                                
                                        bigImage.onload = function ()
                                        //for firefox
                                        {
                                                newwidth=bigImage.width+40;
                                                newheight=imgPopup.document.body.scrollHeight+60;
                                                imgPopup.resizeTo(newwidth,newheight);
                                                imgPopup.window.focus;
                                        }
                                                                                window.onload = function ()
                                        //for firefox
                                        {
                                                newwidth=bigImage.width+40;
                                                newheight=imgPopup.document.body.scrollHeight+60;
                                                imgPopup.resizeTo(newwidth,newheight);
                                                imgPopup.window.focus;
                                        }
                                                                                imgPopup.onblur=imgPopup.window.focus;
}

function docPopup(url){
                                                window.open(url,'popup');
}

function popupLinks(){
if(!document.getElementById)return false;
var aLinks=document.getElementsByTagName('a');
//alert('running script');
for (var i=0;i<aLinks.length;i++) {
        if (aLinks[i].className == 'popup')
                        {
                                aLinks[i].onclick = function ()
                                {
                                        //alert(linktype);]
                                        //
                                        var linktype=this.getAttribute('href');
                                        var linktype_array=linktype.split(".");
                                        var linkex=linktype_array[linktype_array.length-1];
                                                                                linkex=linkex.toLowerCase();
                                        //if(this.protocol=="file:"){
                                        if(linkex=='jpg' || linkex=='gif' || linkex=='ipx'){
                                                imgPopup(this.getAttribute('href'),this.getAttribute('title') );}
                                        else{docPopup(this.getAttribute('href'));}
                                return false;
                                }
                                //return false;
                        }
                        aLinks[i].onkeypress = aLinks[i].onclick;
                }
}

function toggleAdvancedOptions(){
	x=document.getElementById('advsearch');
	var newcontrol=document.getElementById('newcontrol');
	if (x.style.display=='none')
	{
		x.style.display='block';
		newcontrol.innerHTML='<a href="javascript:toggleAdvancedOptions();" >more options</a>  - ';
		}
	else{x.style.display='none';
	newcontrol.innerHTML='<a href="javascript:toggleAdvancedOptions();" >more options</a> + ';}	
}



function hideAdvancedSearch(){
	if (!document.getElementById('Diary')) return false;
	var x=document.getElementById('advsearch');
	var newcontrol=document.getElementById('newcontrol');
	newcontrol.innerHTML='<a href="javascript:toggleAdvancedOptions();" >more options</a> + ';
	x.style.display='none';
	//alert(x.innerHTML);   
}

///from http://www.iqcontent.com/blog/files/taglinks.js ///

function addtrackerlistener(obj) {
	if (obj.addEventListener) {
		obj.addEventListener('click', trackfiles, true);
	} else if (obj.attachEvent) {
		obj.attachEvent("on" + 'click', trackfiles);
	}
}

function trackfiles(array_element) {
	file_path = "";
	if (location.host != this.hostname) {
		file_path = "/exlinks/" + ((array_element.srcElement) ? "/" + array_element.srcElement.hostname : this.hostname);
	}
	file_path = file_path + ((array_element.srcElement) ? "/" + array_element.srcElement.pathname : this.pathname);
	urchinTracker(file_path);
}


function cdsCheckUrchinDownloads(){
var hrefs = document.getElementsByTagName("a");
var link_path = "";
for (var l = 0; l < hrefs.length; l++) {
		try {
			var link_path = hrefs[l].pathname;
			if (location.host == hrefs[l].hostname) {
				if (link_path.match(/\.(doc|pdf|xls|ppt|zip|txt|vsd|vxd|js|css|rar|exe|wma|mov|avi|wmv|mp3)$/)) {
					addtrackerlistener(hrefs[l]);
				}
			} else {
				addtrackerlistener(hrefs[l]);
			}
		}
		catch(err) { }
}
}


//// end urchin script///

//////// begin ross' validation script ////////

/*function automarketing(){
	alert("automarketing running");
	var automarketing = document.getElementsByTagName("input").ClassName('check').checked = true;
if (!document.getElementsByTagName("input").ClassName('check').checked = true;){
return false;
	
}
}
*/
function checkform(){
	
	if(!document.getElementById("email")){
		return false;
	}

var email = document.getElementById("email");
var name = document.getElementById("name");

//alert("checkform is running");

if (email.value == "")
  {
    alert("You must include a valid email address for a response.");
			email.style.color = '#ff0000';
	email.style.border = '2px solid #ff0000';
	email.style.FontSize = '16px';
	
	return false;
  }
  if ((email.value.indexOf ('@',0) == -1 ||
   email.value.indexOf ('.',0) == -1) &&
   email.value != "")
  
  {
    alert("Please ensure the email address you entered is valid.");
		email.style.color = '#ff0000';
	email.style.border = '2px solid #ff0000';
	email.style.FontSize = '16px';
	return false;
	}
	else if (name.value == ""){
			name.style.color = '#ff0000';
	name.style.border = '2px solid #ff0000';
	name.style.FontSize = '16px';
	
	alert("you have entered incorrect data into the name field");
	return false;
	}
	else if (name  && email != ""){
		document.getElementsByTagName("input").checked = true;
		
	}
		
return true;
}



function loadfunctions(){
	
	//alert('running');
		
		if(!document.getElementById('bblitebar'))
        {//functions not run in edit mode
		//insertmailto();	
       	//makeheadergraphic();
       	swapflash('flash/header02.swf','flashheader',364,150,'flashmovie',null);
        popupLinks();
		
		cdsCheckUrchinDownloads();
		}
}




window.onload=loadfunctions;
