/* MAP CODE */
	var mapwin;
	var GLOBALS = new Array();
	gMapsLoader = function() {
		var preloader = 'MapGooglePreloader_' + GLOBALS.MapFieldsNumber;
		GLOBALS[preloader] = function() {
			google.load("maps", "2", {"callback" : function() {}});
    	}

		if (window.google) {
        	GLOBALS[preloader]();
		}
		else {
        	var script = document.createElement("script");
			script.src = "http://www.google.com/jsapi?key=" + googleMaps_api_key + "&callback=GLOBALS." + preloader;
			script.type = "text/javascript";
			document.getElementsByTagName("head")[0].appendChild(script);
		}
		return  true;
	}
	
	showMap = function(){
		mapwin = new Ext.Window({
		layout: 'fit',
		title: 'Find a short break service',
        closeAction: 'close',
		width:500,
		height:500,
		modal: true,
		border: false,
		plain : true,
		closable:false,
		buttonAlign: 'center',
		buttons: [{
			text: 'Close',
			handler: function(){mapwin.close();},
			scope: this
		}],
		tbar: new Ext.Toolbar({
        			items:[
        				{text: 'Search for your local scheme:'},
        				{
                    		xtype: 'textfield',
                    		id: 'locationsearch',
                    		selectOnFocus: true,
                    		width: 150
						},
						{
							xtype: 'button',
							text: 'Go',
							id: 'mapwin_search_text',
							handler : function(){performMapSearch();}
						}
        			]
        		}),
                items: {
                   	xtype: 'gmappanel',
                    region: 'center',
                    zoomLevel: 5,
                    gmapType: 'map',
                    mapConfOpts: ['enableScrollWheelZoom','enableDoubleClickZoom','enableDragging'],
                    mapControls: ['GSmallMapControl','GMapTypeControl','NonExistantControl'],
                    setCenter: {geoCodeAddr: 'UK', marker: {title: 'United Kingdom'}},
                    listeners: {
                	 	'mapready': function(){showMarkers();}
                	}
                }
            });
        	mapwin.show();
        	new Ext.ToolTip({
				title: '',
				target: 'mapwin_search_text',
				html: "To find a short break service in your area please type your postcode, town or county into the search field and click 'Go'."
			});
	}
	
	performMapSearch = function(){
    	var query = Ext.getCmp('locationsearch').getValue() + " UK";
    	mapwin.items.get(0).geoCodeSearch(query);
    }
	
	showMarkers = function(){
		var conn = new Ext.data.Connection();
		conn.request({
			url: '/echo/modules/locations/markers.jsp',
			method: 'get',
			success: function(result){
				var data = eval('('+result.responseText+')');
				mapwin.items.get(0).addMarkers(data);	
         	}
		});
	}
/* SIGNUP CODE */
	Ext.ns('WIDGETS.SCNMEMBERSHIP');
	WIDGETS.SCNMEMBERSHIP.strings = new Array();
	WIDGETS.SCNMEMBERSHIP.strings[0] = 'Saving Membership';
	WIDGETS.SCNMEMBERSHIP.strings[1] = 'Please wait while the membership is created';
	WIDGETS.SCNMEMBERSHIP.strings[2] = 'Membership submitted';
	WIDGETS.SCNMEMBERSHIP.strings[3] = 'Your membership application has been submitted successfully. We will be in contact shortly';
	WIDGETS.SCNMEMBERSHIP.strings[4] = 'Membership could not be saved';
	WIDGETS.SCNMEMBERSHIP.strings[5] = 'Connection error';
	WIDGETS.SCNMEMBERSHIP.strings[6] = 'Please contact support with the following: Status - ';
	WIDGETS.SCNMEMBERSHIP.strings[7] = 'Validation failure';
	WIDGETS.SCNMEMBERSHIP.strings[8] = 'Please fill in the required fields';
	WIDGETS.SCNMEMBERSHIP.strings[9] = 'Unknown error';
	WIDGETS.SCNMEMBERSHIP.strings[10]= 'Loading Membership Data';
	WIDGETS.SCNMEMBERSHIP.strings[11]= 'Membership data not be loaded';
	WIDGETS.SCNMEMBERSHIP.strings[12]= 'Permission Denied';
		
	var signUpMembershipFormWin = null;
	signupForm = function(){
		signUpMembershipFormWin = new Ext.Window({
			layout: 'fit',
			title: 'Sign Up for Membership',
			width:550,
			height:500,
			id: "signupformwin",
			loadScripts: true,
			shadow:true,
			autoScroll: true,
			modal : true,
			plain : true,
			closable:false,
			border: false,
			buttonAlign: 'center',
			buttons: [
				{
					text: 'Submit',
					handler: function(){
						WIDGETS.SCNMEMBERSHIP.SHAREDCARED_MEMBERSHIP.getForm().submit({
						method:'post',
							waitTitle:WIDGETS.SCNMEMBERSHIP.strings[0],
							waitMsg:WIDGETS.SCNMEMBERSHIP.strings[1],
							url:'/echo/modules/scnmembership/signup.jsp',
							params: {"action" : "addRecordTwo"},
							success : function (fForm, action) {
								Ext.MessageBox.alert(WIDGETS.SCNMEMBERSHIP.strings[2], WIDGETS.SCNMEMBERSHIP.strings[3]);
								signUpMembershipFormWin.close();
							},
							failure : function (fForm, action) {
								if(action.failureType == 'server'){
									var message = action.result.message;
									if(message == 100){message = WIDGETS.SCNMEMBERSHIP.strings[12];}
									Ext.MessageBox.alert(WIDGETS.SCNMEMBERSHIP.strings[4], message);
								}
								else if (action.failureType == Ext.form.Action.LOAD_FAILURE) {
									Ext.MessageBox.alert(WIDGETS.SCNMEMBERSHIP.strings[4], action.response.responseText);
								}
								else if (action.failureType == Ext.form.Action.CONNECT_FAILURE) {
									Ext.MessageBox.alert(WIDGETS.SCNMEMBERSHIP.strings[5], WIDGETS.SCNMEMBERSHIP.strings[6] + action.response.status +", Status Text: " + action.response.statusText);
								}
								else if (action.failureType == Ext.form.Action.CLIENT_INVALID) {
									Ext.MessageBox.alert(WIDGETS.SCNMEMBERSHIP.strings[7], WIDGETS.SCNMEMBERSHIP.strings[8]);
								}
								else{
									Ext.MessageBox.alert(WIDGETS.SCNMEMBERSHIP.strings[4], WIDGETS.SCNMEMBERSHIP.strings[9]);
								}
								
							}
						});
					},
					scope: this
				},
				{
					text: 'Close',
					handler: function(){signUpMembershipFormWin.close();},
					scope: this
				}
			],
			keys: {
				key: 27, // Esc key
				handler: function(){signUpMembershipFormWin.close();},
				scope: this
			}
		});
		
		signUpMembershipFormWin.show();
		signUpMembershipFormWin.load({
			url: '/echo/modules/scnmembership/signup.jsp',
			method: 'post',
			params: {"action" : "addRecord", "targetpanelid" : "signupformwin"},
			text: "Loading...",
			scripts: true
		});
	}
	
	/* SUBSCRIBE CODE */
	
	var subscribeEmailFormWin = null;
	subscriberForm = function(){
		subscribeEmailFormWin = new Ext.Window({
			layout: 'fit',
			title: 'Subscribe to news',
			width:550,
			height:500,
			id: "signupformwin",
			loadScripts: true,
			shadow:true,
			autoScroll: true,
			modal : true,
			plain : true,
			closable:false,
			border: false,
			buttonAlign: 'center',
			buttons: [
				{
					text: 'Save',
					handler: function(){
						subscribeEmailFormWin.items.get(0).getForm().submit({
							method:'post',
							waitTitle:'Saving Request',
							waitMsg:'Please wait while your request is sent',
							url:'/echo/modules/formbuilder/submit.jsp',
							params: {"formcode" : WIDGETS.SUBSMANAGER.SUBSADDPANEL.formcode},
							success : function (fForm, action) {
								Ext.MessageBox.alert('Query saved', "The query has been sent succesfully");
								subscribeEmailFormWin.close();
							},
							failure : function (fForm, action) {
								if(action.failureType == 'server'){
									Ext.MessageBox.alert('Query could not be sent', action.result.message);
								} 
								else if (action.failureType == Ext.form.Action.LOAD_FAILURE) {
									Ext.MessageBox.alert('Query could not be sent', action.response.responseText);
								}
								else if (action.failureType == Ext.form.Action.CONNECT_FAILURE) {
									Ext.MessageBox.alert("Connection error", "Please contact support with the following: " + "Status: " + action.response.status +", Status Text: " + action.response.statusText);
								}
								else if (action.failureType == Ext.form.Action.CLIENT_INVALID) {
									Ext.MessageBox.alert('Validation failure', "Please fill in the required fields");
								}
								else{
									Ext.MessageBox.alert('Query could not be sent', "Your message could not be sent, please try again later.");
								}
							}
						});
					},
					scope: this
				},
				{
					text: 'Close',
					handler: function(){subscribeEmailFormWin.close();},
					scope: this
				}
			],
			keys: {
				key: 27, // Esc key
				handler: function(){subscribeEmailFormWin.close();},
				scope: this
			}
		});
		
		subscribeEmailFormWin.show();
	
		subscribeEmailFormWin.load({
			url: '/echo/modules/subscriptionmanager/input.jsp',
			method: 'post',
			params: {"action" : "add", "targetpanelid" : "signupformwin"},
			text: "Loading...",
			scripts: true
		});
		
	}
	
	/*REGISTER CODE */
	
	Ext.ns('WIDGETS.SCNREGISTRATION');
	WIDGETS.SCNREGISTRATION.strings = new Array();
	WIDGETS.SCNREGISTRATION.strings[0] = 'Saving Form';
	WIDGETS.SCNREGISTRATION.strings[1] = 'Please wait while the application is created';
	WIDGETS.SCNREGISTRATION.strings[2] = 'Form submitted';
	WIDGETS.SCNREGISTRATION.strings[3] = 'Your application has been submitted successfully. We will be in contact shortly';
	WIDGETS.SCNREGISTRATION.strings[4] = 'Form could not be saved';
	WIDGETS.SCNREGISTRATION.strings[5] = 'Connection error';
	WIDGETS.SCNREGISTRATION.strings[6] = 'Please contact support with the following: Status - ';
	WIDGETS.SCNREGISTRATION.strings[7] = 'Validation failure';
	WIDGETS.SCNREGISTRATION.strings[8] = 'Please fill in the required fields';
	WIDGETS.SCNREGISTRATION.strings[9] = 'Unknown error';
	WIDGETS.SCNREGISTRATION.strings[10]= 'Loading Application Data';
	WIDGETS.SCNREGISTRATION.strings[11]= 'Data not be loaded';
	WIDGETS.SCNREGISTRATION.strings[12]= 'Permission Denied';
	
	
	
	var resisterFormWin = null;
	registrationFrm = function(){
		resisterFormWin = new Ext.Window({
			layout: 'fit',
			title: 'Registration',
			width:550,
			height:500,
			id: "regformwin",
			loadScripts: true,
			shadow:true,
			autoScroll: true,
			modal : true,
			plain : true,
			closable:false,
			border: false,
			buttonAlign: 'center',
			buttons: [
				{
					text: 'Submit',
					handler: function(){
					
					WIDGETS.SCNREGISTRATION.REGISTRATION_FORM.getForm().submit({
						method:'post',
							//waitTitle:WIDGETS.SCNMEMBERSHIP.strings[0],
							//waitMsg:WIDGETS.SCNMEMBERSHIP.strings[1],
							url:'/echo/modules/scnmembership/registration.jsp',
							params: {"action" : "addRecordTwo"},
							success : function () {
								Ext.MessageBox.alert(WIDGETS.SCNREGISTRATION.strings[2], WIDGETS.SCNREGISTRATION.strings[3]);
								resisterFormWin.close();
							},
							failure : function (fForm, action) {
								if(action.failureType == 'server'){
									var message = action.result.message;
									if(message == 100){message = WIDGETS.SCNREGISTRATION.strings[12];}
									Ext.MessageBox.alert(WIDGETS.SCNREGISTRATION.strings[4], message);
								}
								else if (action.failureType == Ext.form.Action.LOAD_FAILURE) {
									Ext.MessageBox.alert(WIDGETS.SCNREGISTRATION.strings[4], action.response.responseText);
								}
								else if (action.failureType == Ext.form.Action.CONNECT_FAILURE) {
									Ext.MessageBox.alert(WIDGETS.SCNREGISTRATION.strings[5], WIDGETS.SCNREGISTRATION.strings[6] + action.response.status +", Status Text: " + action.response.statusText);
								}
								else if (action.failureType == Ext.form.Action.CLIENT_INVALID) {
									Ext.MessageBox.alert(WIDGETS.SCNREGISTRATION.strings[7], WIDGETS.SCNREGISTRATION.strings[8]);
								}
								else{
									Ext.MessageBox.alert(WIDGETS.SCNREGISTRATION.strings[4], WIDGETS.SCNREGISTRATION.strings[9]);
								}
							
							}
						});					
					},
					scope: this
				},
				{
					text: 'Close',
					handler: function(){resisterFormWin.close();},
					scope: this
				}
			],
			keys: {
				key: 27, // Esc key
				handler: function(){resisterFormWin.close();},
				scope: this
			}
		});
		
		resisterFormWin.show();
	
		resisterFormWin.load({
			url: '/echo/modules/scnmembership/registration.jsp',
			method: 'post',
			params: {"action" : "add", "targetpanelid" : "regformwin"},
			text: "Loading...",
			scripts: true
		});
		
	}
	
	
	
	
	
	/* MENU CODE */
	function formatTopMenu(jsonData){
		var js = "<ul>";
		for(var i = 0, l = jsonData.length; i < l; i++){
			if(jsonData[i].hidden == false){
				if(document.location.pathname == jsonData[i].link){
					js+='<li><a href="'+ jsonData[i].link +'" title="'+ jsonData[i].summary +'" class="selected">'+ jsonData[i].text +'</a><\/li>';
				}
				else{
					js+='<li><a href="'+ jsonData[i].link +'" title="'+ jsonData[i].summary +'">'+ jsonData[i].text +'</a><\/li>';
				}
			}
		}
		js+="<\/ul>";
		return(js);
	}
	
	function formatSideMenu(jsonData){
		var js = "<ul>";
		for(var i = 0, l = jsonData.length; i < l; i++){
			if(jsonData[i].hidden == false){
				if(document.location.pathname == jsonData[i].link){
					js+='<li class="'+ jsonData[i].stylename +'"><a href="'+ jsonData[i].link +'" title="'+ jsonData[i].summary +'" class="'+ jsonData[i].stylename +'_link selected">'+ jsonData[i].text +'</a><\/li>';
				}
				else{
					js+='<li class="'+ jsonData[i].stylename +'"><a href="'+ jsonData[i].link +'" title="'+ jsonData[i].summary +'" class="'+ jsonData[i].stylename +'_link">'+ jsonData[i].text +'</a><\/li>';
				}
			}
		}
		js+="<\/ul>";
		return(js);
	}
	
	function formatMainMenu(jsonData, menuid){
		var js = "<ul>";
		for(var i = 0, l = jsonData.length; i < l; i++){
			if(jsonData[i].hidden == false){
				if(menuid == jsonData[i].id){
					js+='<li><a href="'+ jsonData[i].link +'" title="'+ jsonData[i].summary +'" class="selected">'+ jsonData[i].text +'</a><\/li>';
				}
				else{
					js+='<li><a href="'+ jsonData[i].link +'" title="'+ jsonData[i].summary +'">'+ jsonData[i].text +'</a><\/li>';
				}
			}
		}
		js+="<\/ul>";
		return(js);
	}
	
	function makeNameLink(s){
		s = s.replace(/\s/g,'_');
		s = s.replace(/[^a-zA-Z0-9_]/g,'');
		return(s);
	}
	
	function formatInPageMenu(jsonData, pageid){
		var js = "<ul>";
		for(var i = 0, l = jsonData.length; i < l; i++){
			//if(jsonData[i].hidden == true){continue;}
				for(var j = 0, m = jsonData[i].children.length; j < m; j++){
					/* if it has children */
					if(jsonData[i].children[j]){
						if(jsonData[i].children[j].children){
							if(!jsonData[i].children[j].hidden){
								if(jsonData[i].children[j].link){
									var link = jsonData[i].children[j].link;//"/title/" + makeNameLink(jsonData[i].children[j].text);
									js+='<li class="inpagemenuheadonetd"><a class="inpagemenuone" title="'+ jsonData[i].children[j].summary +'" href="'+ link +'">'+ jsonData[i].children[j].text +'</a></li></tr>';
								}
								else{
									js+='<li class="inpagemenuheadonetd">'+ jsonData[i].children[j].text +'</li></tr>';
								}
							}
						}
						else{//otherwise
							if(jsonData[i].children[j].text != "Home"){
								if(pageid == jsonData[i].children[j].id){
									var link = "/title/" + makeNameLink(jsonData[i].children[j].text);
									js+='<li class="inpagemenuonetd inpagemenuselected"><a class="inpagemenuone" title="'+ jsonData[i].children[j].summary +'" href="'+ link +'">'+ jsonData[i].children[j].text +'</a></li>';
								}
								else{
									var link = "/title/" + makeNameLink(jsonData[i].children[j].text);
									js+='<li class="inpagemenuonetd"><a id="pmenuitemlink'+ jsonData[i].children[j].id +'" title="'+ jsonData[i].children[j].summary +'" class="inpagemenuone" href="'+ link +'">'+ jsonData[i].children[j].text +'</a></li>';
								}
							}
						}
					}
				}
			}						
		js+="<\/ul>";
		return(js);
	}
	
	function insertTopMenu(parent, catid){
		var conn = new Ext.data.Connection();
		conn.request({
			url: '/echo/modules/categories/menulist.jsp?catid=' + catid,
			method: 'get',
			success: function(result){
				var jsonData = Ext.util.JSON.decode(result.responseText);
				var js = formatTopMenu(jsonData);
				$(parent).innerHTML = js;
			}
		});
	}
	
	function insertSideMenu(parent, catid){
		var conn = new Ext.data.Connection();
		conn.request({
			url: '/echo/modules/categories/menulist.jsp?catid=' + catid,
			method: 'get',
			success: function(result){
				var jsonData = Ext.util.JSON.decode(result.responseText);
				var js = formatSideMenu(jsonData);
				$(parent).innerHTML = js;
			}
		});
	}
	
	function insertMainMenu(parent, catid, mid){
		var conn = new Ext.data.Connection();
		conn.request({
			url: '/echo/modules/categories/menulist.jsp?catid=' + catid,
			method: 'get',
			success: function(result){
				var jsonData = Ext.util.JSON.decode(result.responseText);
				var js = formatMainMenu(jsonData, mid);
				$(parent).innerHTML = js;
			}
		});
	}

	function insertPageMenu(catid, mid, pid){
		var conn = new Ext.data.Connection();
		conn.request({
			url: '/echo/modules/categories/menulist.jsp?catid=' + catid + '&mid='+mid,
			method: 'get',
			success: function(result){
				var jsonData = Ext.util.JSON.decode(result.responseText);
				var pageid = pid;
				var js = formatInPageMenu(jsonData, pageid);
				$('inpagemenu').innerHTML = js;
			}
		});
	}
	
	/* TEMPORARY FIX FOR IE 6 & 7 TRIGGER FIELDS */
	Ext.form.TriggerField.override({
    afterRender : function(){
        Ext.form.TriggerField.superclass.afterRender.call(this);
        var y;
        if(Ext.isIE && !this.hideTrigger && this.el.getY() != (y = this.trigger.getY())){
            this.el.position();
            this.el.setY(y);
        }
    }
	});
	
    /* SEARCH CODE */
	Ext.onReady(function(){
		var resultTpl = new Ext.XTemplate(
   	     	'<tpl for="."><div class="search-item">',
         	   '<h3><span>{date:date("M j, Y")}<br /><\/span>{title}<\/h3>',
         	   '{summary}',
        	'<\/div><\/tpl>'
    	);
    
    	var ds = new Ext.data.Store({
    	    proxy: new Ext.data.HttpProxy({
    	        url: '/echo/modules/pages/search.jsp'
    	    }),
    	    reader: new Ext.data.JsonReader({
    	        root: 'data',
    	        totalProperty: 'totalCount',
    	        id: 'pageid'
    	    },
    	    [{name: 'title'}, {name: 'pageid'}, {name: 'templateid'}, {name: 'date',type: 'date', dateFormat: 'Y-m-d H:i:s'},{name: 'summary'}]
    	    )
    	});
    
    	if($('search')){
    		var search = new Ext.form.ComboBox({
    	    	store: ds,
    	    	displayField:'title',
    	    	typeAhead: false,
    	    	loadingText: 'Searching...',
    	    	width: 470,
    	    	pageSize:10,
    	    	hideTrigger:true,
    	    	tpl: resultTpl,
    	    	applyTo: 'search',
    	    	itemSelector: 'div.search-item',
    	    	onSelect: function(record){ // override default onSelect to do redirect
    	    		window.location = String.format('/content/{0}?q={1}', record.id, search.getValue());
    	    	}
    		});
    	}
    });
    
    function highlightWord(node,word, tagType, qtitle, qtext, classname) {
    	if(classname == null){classname = "searchword"}
    	
		// Iterate into this nodes childNodes
		if (node.hasChildNodes) {
			var hi_cn;
			for (hi_cn=0;hi_cn<node.childNodes.length;hi_cn++) {
				highlightWord(node.childNodes[hi_cn],word,tagType, qtitle, qtext);
			}
		}
	
		// And do this node itself
		if (node.nodeType == 3) { // text node
			tempNodeVal = node.nodeValue.toLowerCase();
			tempWordVal = word.toLowerCase();
			if (tempNodeVal.indexOf(tempWordVal) != -1) {
				pn = node.parentNode;
				// check if we're inside a "nosearchhi" zone
				checkn = pn;
				while (checkn.nodeType != 9 && 
				checkn.nodeName.toLowerCase() != 'body') { 
				// 9 = top of doc
					if (checkn.className.match(/\bnosearchhi\b/)) { return; }
					checkn = checkn.parentNode;
				}
				if (pn.className != classname) {
					// word has not already been highlighted!
					nv = node.nodeValue;
					ni = tempNodeVal.indexOf(tempWordVal);
					// Create a load of replacement nodes
					before = document.createTextNode(nv.substr(0,ni));
					docWordVal = nv.substr(ni,word.length);
					after = document.createTextNode(nv.substr(ni+word.length));
					hiwordtext = document.createTextNode(docWordVal);
					hiword = document.createElement(tagType);
					hiword.className = classname;
					if(qtext != null){hiword.qtip = qtext;}
					if(qtitle != null){hiword.qtitle = qtitle;}
					hiword.appendChild(hiwordtext);
					pn.insertBefore(before,node);
					pn.insertBefore(hiword,node);
					pn.insertBefore(after,node);
					pn.removeChild(node);
				}
			}
		}
	}

	function searchHighlight(tagType, qtitle, qtext, classname) {
		if (!document.createElement) return;
		ref = document.location.toString();
		if (ref.indexOf('?') == -1) return;
		qs = ref.substr(ref.indexOf('?')+1);
		qsa = qs.split('&');
		for (i=0;i<qsa.length;i++) {
			qsip = qsa[i].split('=');
		        if (qsip.length == 1) continue;
	        	if (qsip[0] == 'q') { // q= for Google, p= for Yahoo
				words = unescape(qsip[1].replace(/\+/g,' ')).split(/\s+/);
		        for (w=0;w<words.length;w++) {
		        	if(words[w].length > 1){
						highlightWord(document.getElementsByTagName("body")[0],words[w], tagType, qtitle, qtext, classname);
					}
	            }
			}
		}
	}
	
	/* JARGON */
	function doJargon(tagType, classname){
		var jargonStore = new Ext.data.Store({
    		proxy: new Ext.data.HttpProxy({url: '/echo/modules/jargon/jlist.jsp'}),
    	    reader: new Ext.data.JsonReader({
    	        	root: 'data',
    	        	totalProperty: 'totalCount',
    	        	id: 'name'
    	    },
    	    	[{name: 'jargon'}, {name: 'description'}]
    	    ),
    	    autoLoad: true,
    	    listeners: {
				scope: this,
				load: function(){
					jargonStore.each(
						function(record){
							var jargon = record.data.jargon;
							var description = record.data.description;
							highlightWord(document.getElementsByTagName("body")[0],jargon, tagType, "Jargon Explained: " + jargon, description, classname);
						}
					);
				}
			}
    	});
    }
    
    /* ADDS DOWNLOAD LINKS TO ANALYTICS BY ATTACHING A LINK AT RUNTIME */							

	function startListening (obj,evnt,func) {
        if (obj.addEventListener) {
                obj.addEventListener(evnt,func,false);
        } else if (obj.attachEvent) {
                obj.attachEvent("on" + evnt,func);
        }
	}

	function trackMailto (evnt) {
        var href = (evnt.srcElement) ? evnt.srcElement.href : this.href;
        var mailto = "/mailto/" + href.substring(7);
        if (typeof(pageTracker) == "object") pageTracker._trackPageview(mailto);
	}

	function trackExternalLinks (evnt) {
        var e = (evnt.srcElement) ? evnt.srcElement : this;
        while (e.tagName != "A") {
                e = e.parentNode;
        }
        var lnk = (e.pathname.charAt(0) == "/") ? e.pathname : "/" + e.pathname;
        if (e.search && e.pathname.indexOf(e.search) == -1) lnk += e.search;
        if (e.hostname != location.host) lnk = "/external/" + e.hostname + lnk;
        if (typeof(pageTracker) == "object") pageTracker._trackPageview(lnk);
	}
	
	Ext.onReady(function(){
		if (document.getElementsByTagName) {
    	    // Initialize external link handlers
    	    var hrefs = document.getElementsByTagName("a");
    	    for (var l = 0; l < hrefs.length; l++) {
					// try {} catch{} block added by erikvold VKI
				try{
		                //protocol, host, hostname, port, pathname, search, hash
		                if (hrefs[l].protocol == "mailto:") {
		                        startListening(hrefs[l],"click",trackMailto);
		                }
		                else if (hrefs[l].hostname == location.host) {
							var path = hrefs[l].pathname + hrefs[l].search;                        
							var isDoc = path.indexOf("filedownload.jsp") != -1
							if (isDoc) { startListening(hrefs[l],"click",trackExternalLinks);}
		                }
		                else {
		                        startListening(hrefs[l],"click",trackExternalLinks);
		                }
				}
				catch(e){
						continue;
				}
    	    }
		}
	});