	try {document.execCommand("BackgroundImageCache",false,true);}catch(err){};

	//xml functions
	function getNodeValue(obj,tag){try{if(obj.getElementsByTagName(tag)[0].firstChild.nodeValue=='null'){return '';}else{return obj.getElementsByTagName(tag)[0].firstChild.nodeValue;}}catch(err){return '';}};
	function getNodeName(obj){return obj.firstChild.nodeName;};
	function getNodeAttribute(obj,attr){try{return obj.getAttribute(attr);}catch(err){return '';}};
	
	//common functions
	function SearchAndReplace(Content,SearchFor,ReplaceWith){var tmpContent=Content;var tmpBefore=new String();var tmpAfter=new String();var tmpOutput=new String();var intBefore=0;var intAfter=0;if(SearchFor.length==0){return;}else{while(tmpContent.toUpperCase().indexOf(SearchFor.toUpperCase())>-1){intBefore=tmpContent.toUpperCase().indexOf(SearchFor.toUpperCase());tmpBefore=tmpContent.substring(0,intBefore);tmpOutput=tmpOutput+tmpBefore;tmpOutput=tmpOutput+ReplaceWith;intAfter=tmpContent.length-SearchFor.length+1;tmpContent=tmpContent.substring(intBefore+SearchFor.length);}return tmpOutput+tmpContent;}};
	function login_Submit(fObj){if(checkForm($(fObj))==true) $(fObj).submit();}
	function noCache(){return Math.random(0,200)+"="+Math.random(0,10);};
	function ajaxRequest_Error(){};
	function open_win(link, win_name, params){window.open(link,win_name.replace("'",""),params);};
	function MM_preloadImages(){var d=document;if(d.images){if(!d.MM_p){d.MM_p=new Array();}var i,j=d.MM_p.length,a=MM_preloadImages.arguments;for(i=0;i<a.length;i++){if(a[i].indexOf("#")!=0){d.MM_p[j]=new Image;d.MM_p[j++].src=a[i];}}}};
	function highlightNavigation(){
		var navBase		= '/press/media/17/';
		var currentURL	= document.location.href;
		var currentPage = currentURL.substring(currentURL.lastIndexOf('/'),currentURL.length);
		if(currentPage.indexOf('/index')>-1 || currentPage=='/') {
			$('nav_home').src 				= navBase + 'nav_home_over.gif';
			$('nav_home').setAttribute('onmouseover','');
			$('nav_home').setAttribute('onmouseout','');
		}
		if(currentPage.indexOf('/news')>-1) {
			$('nav_news').src 				= navBase + 'nav_announcements_over.gif';
			$('nav_news').setAttribute('onmouseover','');
			$('nav_news').setAttribute('onmouseout','');
		}
		if(currentPage.indexOf('/program')>-1) {
			$('nav_programs').src 			= navBase + 'nav_programs_over.gif';
			$('nav_programs').setAttribute('onmouseover','');
			$('nav_programs').setAttribute('onmouseout','');
		}
		if(currentPage.indexOf('/imagery')>-1) {
			$('nav_imagery').src 			= navBase + 'nav_images_over.gif';
			$('nav_imagery').setAttribute('onmouseover','');
			$('nav_imagery').setAttribute('onmouseout','');
		}
		if(currentPage.indexOf('/corporate')>-1) {
			$('nav_corporate').src 			= navBase + 'nav_corporate_over.gif';
			$('nav_corporate').setAttribute('onmouseover','');
			$('nav_corporate').setAttribute('onmouseout','');
		}
		if(currentPage.indexOf('/contact')>-1) {
			$('nav_contact').src 			= navBase + 'nav_contact_over.gif';
			$('nav_contact').setAttribute('onmouseover','');
			$('nav_contact').setAttribute('onmouseout','');
		}
	};
	
	//site search functions
	function search_Submit(sObj){
		if($F(sObj)!=''){
			if(document.getElementById('page_id')) {
				document.location.href='/press/search_bbca.jsp?kword='+$F(sObj)+'&page_id='+$F('page_id');
			}
			else {
				document.location.href='/press/search_bbca.jsp?kword='+$F(sObj);
			}
		}
		else{
			alert('Please enter a keyword');
		}
	};
	function search_Page(pNum,sObj){$('page_id').value=pNum;search_Submit(sObj);};							

	//cookie functions
	function createCookie(name,value,days){if(days){var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires=';expires='+date.toGMTString();}else{var expires='';}document.cookie=name+'='+value+expires+';path=/';};
	function readCookie(name){var nameEQ=name+"=";var ca=document.cookie.split(';');for(var i=0;i<ca.length;i++){var c=ca[i];while(c.charAt(0)==' ')c=c.substring(1,c.length);if(c.indexOf(nameEQ)==0)return c.substring(nameEQ.length,c.length);}return null;};
	function eraseCookie(name){createCookie(name,"",-1);};

	//site user functions
	var standardLoginLinks 	= '<p class="grey px10 right" style="padding: 5px 10px 0px;"><a href="/press/register.jsp" class="grey px10">Register</a> &nbsp;|&nbsp; <a href="#" onclick="loginDialog();return false;" class="grey px10">Login</a></p>';
	var loggedInLoginLinks 	= '<p class="grey px10 right" style="padding: 5px 10px 0px;"><a href="/press/profile.jsp" class="grey px10">Welcome, <iptag:displayname /></a> &nbsp;|&nbsp; <a href="#" onclick="logout();return false;" class="grey px10">Sign Out</a></p>';
	function showLoginLink(){if(isLoggedIn()==true){$('login_links').innerHTML=loggedInLoginLinks.replace('<iptag:displayname />',readCookie('username'));}else{$('login_links').innerHTML=standardLoginLinks;}};
	function showTicker(){
		var so = new SWFObject("/press/media/17/ticker.swf?press/rss/tickernews.xml","ticker","929","25","7");
		so.addParam("wmode","transparent");
		so.addParam("SCALE", "noborder"); 
		so.write("flash_ticker");
	};
	function isLoggedIn(){if(readCookie('bbcaPress')){return true;}return false;};
	function logout(){eraseCookie('bbcaPress');eraseCookie('email');eraseCookie('username');showLoginLink();};
	function login(username, email){createCookie('bbcaPress','true',30);createCookie('username',username,30);createCookie('email',email,30);};
	function registerUser() {
		if(checkForm($('registration_form'))){
			if($F('password')!=$F('re_password')){
				alert('Passwords do not match');
			}
			else {
				
					new Ajax.Request
					(
						'processregister.jsp',
						{
							method:'POST',
							parameters: $('registration_form').serialize(),
							onFailure:ajaxRequest_Error,
							onSuccess:function (xml)
							{
								var insertStat = xml.responseXML.getElementsByTagName('insert')[0].firstChild ? xml.responseXML.getElementsByTagName('insert')[0].firstChild.data : '';
								var error = xml.responseXML.getElementsByTagName('error')[0].firstChild ? xml.responseXML.getElementsByTagName('error')[0].firstChild.data : 'Unknown error';

								if (insertStat == ' Success ')
								{
									var url			= document.location.href;
									var aryCurLoc 	= url.split('/');
									aryCurLoc[aryCurLoc.length - 1] = 'registerthankyou.jsp';
									window.location = aryCurLoc.join('/');
								}
								else
								{
									alert('The following error occured while trying to create your user account:\n' + error);
								}
							}
						}
					);
			}
		}
	};
	function downloadAsset(filename,program_id){
		if(isLoggedIn()==true){
			//show the file download
		}
		else {
			downloadLoginDialog();
		}
	};

	//form functions
	var dfltValue   = '**NO VALUE**';
	var dfltChars   = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.?-()[]+=_-;:/#@$%&!,*<>\"\'\n\r ';
	var dfltMethod  = 'POST';
	
	function checkForm(object){
		errFlag = false;
	    for(var i=0;i<object.elements.length;i++) {
	    	if(object.elements[i].attributes['id']) {
				theO		= $(object.elements[i]);
				oType		= theO.type;
		        oName  		= theO.attributes['id'].value;
				theO.name 	= oName;
		        oValue 		= $F(theO);
			    (theO.attributes["required"]) ? oReqd=true : oReqd = false;
			   	(theO.attributes["alert"]) ? oAlert=theO.attributes['alert'].value : oAlert = '';
				(theO.attributes["highlight"]) ? oHighlight=theO.attributes['highlight'].value : oHighlight = '';
		       	(theO.attributes["chars"]) ? oChars=theO.attributes['chars'].value : oChars = dfltChars;
		        (theO.attributes["editor"]) ? oEditor=true : oEditor = false;
		        (theO.attributes["parent"]) ? oParent=theO.attributes['parent'].value : oParent = '';
				(theO.attributes["minLen"]) ? oMin=theO.attributes['minLen'].value : oMin = 1;
		        (theO.attributes["maxLen"]) ? oMax=theO.attributes['maxLen'].value : oMax = 100;
				if(oReqd==true||(document.getElementById(oParent)&&oParent!=''&&$(oParent).checked==true)) {
		        	if(oEditor==true) {
						var tmpValue = getEditor(oName);
						if(tmpValue.length<oMin || tmpValue.length>oMax) {
							errFlag=true;
							if(oHighlight!='') theO.className = oHighlight;
							theO.focus();
							if(oAlert!='') alert(oAlert);
							break;
						}
		        	}
		        	else {
			            if(oName.toLowerCase().indexOf('email')>-1) { 
			                if(isValidEmail(oValue)==false) {
			                	errFlag = true;
								if(oHighlight!='') theO.addClassName(oHighlight);
								theO.focus();
								if(oAlert!='') alert(oAlert);
								break;
			                }
			             } 
			             else if(validate(oValue,oChars)==false||oValue.length<oMin||oValue.length>oMax){
			             	errFlag = true;
							if(oHighlight!='') {
								theO.addClassName(oHighlight);
							}
							theO.focus();
							if(oAlert!='') alert(oAlert);
							break;
			             }
			     	}
		        }
			}
	    }
		if(errFlag==false) {
			return true;
		}
		else {
			return false;
		}
	};
		
	function isValidEmail(string){if(string.length<1)return false;if(string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)!=-1){return true;}else{return false;}};
	function validate(strVl,strChrs){if(!strVl) return false;if(strVl==dfltValue)return false;if(strVl.length<1)return false;for(i=0;i<strVl.length;i++){if(strChrs.indexOf(strVl.charAt(i))==-1)return false;}return true;};

	function loginDialog()
	{
		var loginHTML = ''
			+	'<div style="clear:both">'
			+	'</div>'
			+	'<form id="loginForm">'
			+	'<table width="320px">'
			+		'<tr>'
			+			'<td colspan="3">'
			+				'<table>'
			+					'<tr>'
			+						'<td align="right" class="grey 11px" width="130px">'
			+							'Email Address:'
			+						'</td>'
			+						'<td align="left">'
			+							'<input type="text" required alert="Please enter an email address." id="login_email">'
			+						'</td>'
			+					'</tr>'
			+					'<tr>'
			+						'<td colspan="2">'
			+							'<div style="clear:both">'
			+							'</div>'
			+						'</td>'
			+					'</tr>'
			+					'<tr>'
			+						'<td align="right" class="grey 11px">'
			+							'Password:'
			+						'</td>'
			+						'<td align="left">'
			+							'<input type="password" required alert="Please enter password." id="login_password">'
			+						'</td>'
			+					'</tr>'
			+				'</table>'
			+			'</td>'
			+		'</tr>'
			+		'<tr>'
			+			'<td colspan="3">'
			+				'<div style="clear:both">'
			+				'</div>'
			+			'</td>'
			+		'</tr>'
			+		'<tr>'
			+			'<td width="70px">&nbsp;</td>'
			+			'<td align="left">'
			+				'<a href="#" onclick="Dialog.closeInfo();forgotPassDialog();" class="red 11px">Forgot your password?</a>'
			+			'</td>'
			+			'<td align="right">'
			+				'<a href="register.jsp" class="red 11px">Register</a>'
			+			'</td>'
			+		'</tr>'
			+	'</table>'
			+	'</form>'
			+	'<div style="clear:both">'
			+	'</div>';

		Dialog.confirm
		(
			loginHTML,
			{
				className:"alphacube",
				width:400, 
				okLabel: "Login", cancelLabel: "Cancel",
	    		onOk:function(win)
				{
					var login_email = $('login_email').value;
					var login_password = $('login_password').value;

					if (checkForm($('loginForm')))
					{
						new Ajax.Request
						(
							'ajax/loginProcess.jsp',
							{
								method:'POST',
								parameters:'&email=' + login_email + '&password=' + login_password,
								onFailure:ajaxRequest_Error,
								onSuccess:function (xml)
								{
									var response = '';
									var username = '';
									var reason = '';

									if (xml)
									{
										response = xml.responseXML.getElementsByTagName('response')[0].firstChild ? xml.responseXML.getElementsByTagName('response')[0].firstChild.data : 'error';
										if (response == 'success')
											username = xml.responseXML.getElementsByTagName('username')[0].firstChild ? xml.responseXML.getElementsByTagName('username')[0].firstChild.data : 'Unknown';
										else
											reason = xml.responseXML.getElementsByTagName('reason')[0].firstChild ? xml.responseXML.getElementsByTagName('reason')[0].firstChild.data : 'Unknown';
									}
									else
									{
										alert('An error occurred while trying to log in.\nSorry for the inconvenience.');
										return false;
									}

									if (response != 'success')
									{
										alert(reason);
										return false;
									}

									login(username, login_email); 

									Dialog.closeInfo();
									showLoginLink();
									return true;
								}
							}
						);
					}
					else
					{
						return false;
					}
				}
			}
		);
	};

	function forgotPassDialog()
	{
		var loginHTML = ''
			+	'<div style="clear:both">'
			+	'</div>'
			+	'<form id="forgotPassForm">'
			+	'<table width="400">'
			+		'<tr>'
			+			'<td class="grey 11px" align="right">'
			+				'Email Address:'
			+			'</td>'
			+			'<td align="left">'
			+				'<input type="text" id="forgotPass_email">'
			+			'</td>'
			+		'</tr>'
			+	'</table>'
			+	'</form>'
			+	'<div style="clear:both">'
			+	'</div>';

		Dialog.confirm
		(
			loginHTML,
			{
				className:"alphacube",
				width:400, 
				okLabel: "Reset", cancelLabel: "Cancel",
	    		onOk:function(win)
				{
					var email = $('forgotPass_email').value;

					if (checkForm($('forgotPassForm')))
					{
						new Ajax.Request
						(
							'ajax/resetPassword.jsp',
							{
								method:'POST',
								parameters:'&email=' + email,
								onFailure:ajaxRequest_Error,
								onSuccess:function (xml)
								{
									var response = '';

									if (xml)
									{
										response = xml.responseXML.getElementsByTagName('response')[0].firstChild ? xml.responseXML.getElementsByTagName('response')[0].firstChild.data : 'Error';
										if (response != 'password sent')
										{
											alert(response);
											return false;
										}
									}
									else
									{
										alert('An error occurred while trying to reset the password.\nSorry for the inconvenience.');
										return false;
									}

									alert('The password for this account has been reset and the new password has been sent to the email address.');
									Dialog.closeInfo();
									return true;
								}
							}
						);
					}
					else
					{
						return false;
					}
				}
			}
		);
	};

	function downloadLoginDialog()
	{
		var loginHTML = ''
			+	'<div style="clear:both">'
			+	'</div>'
			+	'<span>You must be logged in to download images. Please login below or click \'register\' to request an account.</span><br />'
			+	'<table width="320px">'
			+		'<tr>'
			+			'<td colspan="3">'
			+				'<table>'
			+					'<tr>'
			+						'<td align="right" class="grey 11px" width="130px">'
			+							'Email Address:'
			+						'</td>'
			+						'<td align="left">'
			+							'<input type="text" required alert="Please enter an email address." id="login_email">'
			+						'</td>'
			+					'</tr>'
			+					'<tr>'
			+						'<td colspan="2">'
			+							'<div style="clear:both">'
			+							'</div>'
			+						'</td>'
			+					'</tr>'
			+					'<tr>'
			+						'<td align="right" class="grey 11px">'
			+							'Password:'
			+						'</td>'
			+						'<td align="left">'
			+							'<input type="password" required alert="Please enter password." id="login_password">'
			+						'</td>'
			+					'</tr>'
			+				'</table>'
			+			'</td>'
			+		'</tr>'
			+		'<tr>'
			+			'<td colspan="3">'
			+				'<div style="clear:both">'
			+				'</div>'
			+			'</td>'
			+		'</tr>'
			+		'<tr>'
			+			'<td width="70px">&nbsp;</td>'
			+			'<td align="left">'
			+				'<a href="#" onclick="Dialog.closeInfo();forgotPassDialog();" class="red 11px">Forgot your password?</a>'
			+			'</td>'
			+			'<td align="right">'
			+				'<a href="register.jsp" class="red 11px">Register</a>'
			+			'</td>'
			+		'</tr>'
			+	'</table>'
			+	'<div style="clear:both">'
			+	'</div>';

		Dialog.confirm
		(
			loginHTML,
			{
				className:"alphacube",
				width:400, 
				okLabel: "Login", cancelLabel: "Cancel",
	    		onOk:function(win)
				{
					var login_email = $('login_email').value;
					var login_password = $('login_password').value;

					if (login_email && login_password)
					{
						new Ajax.Request
						(
							'ajax/loginProcess.jsp',
							{
								method:'POST',
								parameters:'&email=' + login_email + '&password=' + login_password,
								onFailure:ajaxRequest_Error,
								onSuccess:function (xml)
								{
									var response = '';
									var username = '';
									var reason = '';
						
									if (xml)
									{
										response = xml.responseXML.getElementsByTagName('response')[0].firstChild ? xml.responseXML.getElementsByTagName('response')[0].firstChild.data : 'error';
										if (response == 'success')
											username = xml.responseXML.getElementsByTagName('username')[0].firstChild ? xml.responseXML.getElementsByTagName('username')[0].firstChild.data : 'Unknown';
										else
											reason = xml.responseXML.getElementsByTagName('reason')[0].firstChild ? xml.responseXML.getElementsByTagName('reason')[0].firstChild.data : 'Unknown';
									}
									else
									{
										alert('An error occurred while trying to log in.\nSorry for the inconvenience.');
										return false;
									}

									if (response != 'success')
									{
										alert('The following error occured while attempting to log in:\n' + reason);
										return false;
									}

									login(username, login_email); 

									Dialog.closeInfo();
									showLoginLink();
									return true;
								}
							}
						);
					}
					else
					{
						alert('A Login ID and a Password must be entered before logging in.');
						return false;
					}
				}
			}
		);
	};

	function downloadCheck(path)
	{
		if (isLoggedIn())
		{
			var url			= document.location.href;
			var aryCurLoc 	= url.split('/');
			aryCurLoc[aryCurLoc.length - 1] = 'download.jsp?file=' + path;
			window.location = aryCurLoc.join('/');
		}
		else
			downloadLoginDialog();
	}

	function loadProfilePassword()
	{
		profilePassword = Math.floor(Math.random()*999999999999) + '';
		$('password').value = profilePassword;
		$('re_password').value = profilePassword;
	}

	function saveProfile() {
		if(checkForm($('profile_form'))){
			if($F('password')!=$F('re_password')){
				alert('Passwords do not match');
			}
			else {
				if (profilePassword == $('password').value)
				{
					$('password').disabled = true;
					$('re_password').disabled = true;
				}

				new Ajax.Request
				(
					'processregister.jsp',
					{
						method:'POST',
						parameters: $('profile_form').serialize(),
						onFailure:ajaxRequest_Error,
						onSuccess:function (xml)
						{
							$('password').disabled = false;
							$('re_password').disabled = false;
							$('saveSuccess').style.visibility='visible';
						}
					}
				);
			}
		}
	};
