addEventToObject = function(obj,evt,func) {
	var oldhandler = obj[evt];
	obj[evt] = (typeof obj[evt] != 'function') ? func : function(ev){oldhandler(ev);func(ev);};
}

toggleDropDown = function(selectorID,selectorIDhide)
{
	$(selectorID).style.display = "block";
	$(selectorIDhide).style.display = "none";
}

showDropDown = function(selectorID,selectorIDhide)
{
	$(selectorID).style.display = "block";
	$(selectorIDhide).style.display = "none";
}

hideDropDown = function(selectorID)
{	
	new Effect.toggle(selectorID,'blind',
	{
		duration: 0.4
	});
}

toggleSelector = function(selectorID)
{	
	new Effect.toggle(selectorID,'appear',
	{
		duration: 0.0
	});
}

showAdvertising = function()
{
	window.setTimeout("$('add-foo-01').style.display = 'block'",500);
	window.setTimeout("$('add-foo-03').style.display = 'block'",500);
}

showSearch = function()
{
	$('search').style.visibility = 'visible';
}

preLoadInterfaceImages = function()
{
	var i = 0;
	imageObj = new Image();
	
	images = new Array();
	images[0]="/images/drop-down/top-left.png"
	images[1]="/images/drop-down/top-center.gif"
	images[2]="/images/drop-down/top-right.png"
	images[3]="/images/drop-down/middle-left.gif"
	images[4]="/images/drop-down/middle-right.png"
	images[5]="/images/drop-down/bottom-right.png"
	images[6]="/images/drop-down/bottom-left.png"
	images[7]="/images/drop-down/bottom-center.png"
	images[8]="/images/modal-windows/top-center-bottom-center.png"
	images[9]="/images/modal-windows/middle-left-middle-right.png"
	images[10]="/images/modal-windows/top-left.png"
	images[11]="/images/modal-windows/top-right.png"
	images[12]="/images/modal-windows/bottom-right.png"
	images[13]="/images/modal-windows/bottom-left.png"
	images[14]="/images/modal-windows/middle-center.png"
	images[15]="/images/drop-down/close.gif"
	images[16]="/images/icons/send-page.gif"
	images[17]="/images/icons/send-page-hover.gif"
	images[18]="/images/icons/add-page.gif"
	images[19]="/images/icons/add-page-hover.gif"
	images[20]="/images/icons/bookmark.gif"
	images[21]="/images/icons/bookmark-hover.gif"
	images[20]="/images/icons/print.gif"
	images[21]="/images/icons/print-hover.gif"

	// start preloading
	for(i=0; i<images.length; i++) 
	{
		imageObj.src=images[i];
	}
}

setFocus = function(selectorID)
{
	document.getElementById(selectorID).select();
}

changeStyle = function(selectorID,selectorClass)
{
	if (document.getElementById(selectorID) != null)
	{
		document.getElementById(selectorID).className = selectorClass;
	}
}

// Handle table zebra striping
// ----------------------------------------------
stripetableBody = function()
{
	if (!document.getElementsByTagName) return false;
	var tableBody = document.getElementsByTagName("tbody");
	for (var i=0; i<tableBody.length; i++)
	{
		if (tableBody[i].getAttribute("class") == "alternateTableRows" || tableBody[i].getAttribute("className") == "alternateTableRows")
		{
			var odd = false;
			var rows = tableBody[i].getElementsByTagName("tr");
			for (var j=0; j<rows.length; j++)
			{
				if (odd == true)
				{
					addClass(rows[j],"alternate");
					odd = false;
      			}
				else
				{
					odd = true;
		  		}
			}
	  	}
	}
}

// Add classes to selectors
// ----------------------------------------------
addClass = function(element,value)
{
	if (!element.className)
	{
    	element.className = value;
	}
	else
	{
    	newClassName = element.className;
	    newClassName+= " ";
	    newClassName+= value;
	    element.className = newClassName;
  	}
}

// Assist the behaviour and presentation of form elements
// ----------------------------------------------
scanForFormElements = function()
{
	if (!document.getElementsByTagName) return false;
	var anchors = document.getElementsByTagName("input");
	for (var i=0; i<anchors.length; i++)
	{
		var anchor = anchors[i];
		if ((anchor.getAttribute("type") == "text") || (anchor.getAttribute("type") == "password"))
		{
			if (anchor.className!="noCSS")
			{
				addClass(anchor,'textfield');	
			}
		}
		if ((anchor.getAttribute("type") == "button") || (anchor.getAttribute("type") == "submit"))
		{
			if (anchor.className!="noCSS")
			{
				addClass(anchor,'button');
			}
		}
	}
}

findLabels = function()
{
	var el = document.getElementsByTagName("label");
	for (i=0;i<el.length;i++)
	{
		var thisId = el[i].getAttribute("for");
		if ((thisId)==null)
		{
			thisId = el[i].htmlFor;
		}
		if(thisId!="")
		{
			el[i].onmouseover = highlightRelationship;
		}
	}
}

highlightRelationship = function()
{
	var thisId = this.getAttribute("for");
	if ((thisId)==null)
	{
		thisId = this.aspxFor;
	}	
	if (document.getElementById(thisId).type=="text") $(thisId).select();
	if (document.getElementById(thisId).type=="password") $(thisId).select();
	if (document.getElementById(thisId).tagName=="textarea") $(thisId).select();
}

// Handle the launching of new browser windows for offsite links as well as non-web files.
// ----------------------------------------------
scanForExternalLinks = function()
{
	if (!document.getElementsByTagName) return false;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++)
	{
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
		{
			anchor.href = "javascript:getOffsiteLink('"+anchor.getAttribute("href")+"');";
		}
		else if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "nonWebDocument")
		{
			anchor.href = "javascript:getFile('"+anchor.getAttribute("href")+"');";
		}
		else if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "popup")
		{
			anchor.href = "javascript:getFile('"+anchor.getAttribute("href")+"');";
		}
	}
}

getOffsiteLink = function(href)
{
	attributes = 'scrollbars=yes,toolbar=yes,menubar=yes,status=yes,directories=no,location=yes,resizable=yes';
	newWindow = window.open(href,'',attributes);
	newWindow.focus();
}

getFile = function(href)
{
	attributes = 'scrollbars=yes,toolbar=no,menubar=no,status=no,directories=no,location=no,resizable=yes';
	newWindow = window.open(href,'',attributes);
	newWindow.focus();
}

// Modify presentation of page if loaded
// ----------------------------------------------
sniffForBodyLoad = function()
{
	if (!document.getElementsByTagName) return false;
	var selectors = document.getElementsByTagName("body");
	var selector = selectors[0];
	addClass(selector,'isLoaded');
}

// Handle the presentation of the search field
// ----------------------------------------------
showKeywordSearch = function()
{
	var selectorID = 'searchContainer';
	if ($(selectorID)!=null)
	{
		$(selectorID).style.visibility = "visible";
	}
}

// Sets the value for the keyword search textfield on various user events
var textfield_keywordSearch = {
	init : function()
		{
		var smartKeyword = document.getElementById('txtKeyword');
		if (smartKeyword)
			{
			addEventToObject(smartKeyword,'onclick',textfield_keywordSearch.click);
			addEventToObject(smartKeyword,'onblur',textfield_keywordSearch.blur);
			}	
		},
	click : function()
		{
		var smartKeyword = document.getElementById('txtKeyword');
		if (smartKeyword.value == "Search...")
			{
			smartKeyword.value = "";
			}
	  	},
	blur : function()
		{
		var smartKeyword = document.getElementById('txtKeyword');
		if (smartKeyword.value == "" || smartKeyword.value == " ") {smartKeyword.value = "Search...";}
		}
	};

// Sets the value for the login form's username
var smartUsername = {
	init : function()
		{
		var usernameInput = $('txtLoginUsername');
		if (usernameInput)
			{
			addEventToObject(usernameInput,'onclick',smartUsername.click);
			addEventToObject(usernameInput,'onblur',smartUsername.blur);
			}	
		},
	click : function()
		{
		var usernameInput = $('txtLoginUsername');
		if (usernameInput.value == "username")
			{
			usernameInput.value = "";
			}
	  	},
	blur : function()
		{
		var usernameInput = $('txtLoginUsername');
		if (usernameInput.value == "" || usernameInput.value == " ") {usernameInput.value = "username";}
		}
	};
	
// Sets the value for the login form's password
var smartPassword = {
	init : function()
		{
		var passwordInput = $('txtLoginPassword');
		if (passwordInput)
			{
			addEventToObject(passwordInput,'onclick',smartPassword.click);
			addEventToObject(passwordInput,'onblur',smartPassword.blur);
			}	
		},
	click : function()
		{
		var passwordInput = $('txtLoginPassword');
		if (passwordInput.value == "password")
			{
			passwordInput.value = "";
			}
	  	},
	blur : function()
		{
		var passwordInput = $('txtLoginPassword');
		if (passwordInput.value == "" || passwordInput.value == " ") {passwordInput.value = "password";}
		}
	};

// Code to work with page sizing and the presentation of modal windows
// ----------------------------------------------
Position.getPageSize = function()
{
	var xScroll, yScroll, scrollOffsetY;
	if (window.innerHeight && window.scrollMaxY)
	{  
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	}
	else if (document.body.scrollHeight > document.body.offsetHeight)
	{	// all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	}
	else
	{	// Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	if (self.pageYOffset)
	{
		scrollOffsetY = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
	{	 // Explorer 6 Strict
		scrollOffsetY = document.documentElement.scrollTop;
	}
	else if (document.body)
	{	// all other Explorers
		scrollOffsetY = document.body.scrollTop;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight)
	{	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{	// Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{	// other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	} 
	
	// for small pages with total height less then height of the viewport
	pageHeight = Math.max(windowHeight,yScroll);
	
	// for small pages with total width less then width of the viewport
	pageWidth = Math.max(windowWidth,xScroll);
	
	return {
		page:
		{
			width: pageWidth,height: pageHeight
		}, 
		window:
		{
			width: windowWidth,height: windowHeight
		},
		scroll:
		{
			top: scrollOffsetY
		}
	};
}

// Modal windows
// ----------------------------------------------
createOverlay = function()
{
	var objBody = document.getElementsByTagName("body").item(0);
	var objOverlay = document.createElement("div");
	
	objOverlay.setAttribute('id','overlay');
	objOverlay.style.display = 'none';
	objBody.appendChild(objOverlay);
}

openModalWindow = function(selectorID)
{
	//var overlayID = 'overlay';
	var v = Position.getPageSize();

	// Turn off scrollbars in the viewport as they render above the overlay //
	var tas = document.getElementsByTagName("textarea");
	for (var i = 0;i<tas.length;i++)
	{
		if (tas[i].className != "scrollOK")
		{
			tas[i].style.overflow = "hidden";
		}
	}
	if (BrowserDetect.browser=="Explorer")
		{
		var sels = document.getElementsByTagName("select");
		for (var s = 0;s<sels.length;s++)
			{
			sels[s].style.visibility = "hidden";
			}		
		}
	
	// Hide flash in the viewport as it interfers with the overlay //
	var flashObjects = (document.getElementsByTagName("object") || document.getElementsByTagName("embed"));
	for (var i = 0;i<flashObjects.length;i++)
	{
		if (flashObjects[i].className != "viewOK")
		{
			flashObjects[i].style.visibility = "hidden";
		}
	}
	
	// Show the overlay and modal window //

	//document.getElementById(overlayID).style.height = v.page.height + "px";
	document.getElementById(selectorID).style.top = (v.scroll.top+((v.window.height/100)*20)) + "px";

	Effect.Appear(selectorID,
	{
		duration: 0.1
	});
}

closeModalWindow = function(selectorID)
{
	//var overlayID = 'overlay';
	Effect.Fade(selectorID,
	{
		duration: 0.1,
		afterFinish:function()
		{
			if (BrowserDetect.browser=="Explorer")
			{
				var sels = document.getElementsByTagName("select");
				for (var s = 0;s<sels.length;s++)
				{
					sels[s].style.visibility = "visible";
				}		
			}
		}
	});
	
	// Turn scrollbars in the viewport back on //
	var tas = document.getElementsByTagName("textarea");
	for (var i = 0;i<tas.length;i++)
	{
		if (tas[i].className != "scrollOK")
		{
			tas[i].style.overflow = "auto";
			//setStyle('textarea','overflow','auto');
		}	
	}
	
	// Restore flash in the viewport //
	var flashObjects = (document.getElementsByTagName("object") || document.getElementsByTagName("embed"));
	for (var i = 0;i<flashObjects.length;i++)
	{
		flashObjects[i].style.visibility = "visible";
	}
}

// Browser detection
// ----------------------------------------------
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{	// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 	// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

// Activate the menu
// ----------------------------------------------
var listMenu = new FSMenu('listMenu',true,'display','block','none');

var arrow = null;
if (document.createElement && document.documentElement)
{
	listMenu.showDelay = 0;
	listMenu.switchDelay = 125;
	listMenu.hideDelay = 400;
	//listMenu.cssLitClass = 'highlighted';
	listMenu.showOnClick = 0;
	listMenu.hideOnClick = true;
	listMenu.animInSpeed = 0.2;
	listMenu.animOutSpeed = 1.0;
	
	//arrow = document.createElement('span');
	//arrow.appendChild(document.createTextNode('>'));
	//arrow.className = 'subind';
	
//  * FSMenu.animSwipeDown is a "swipe" animation that sweeps the menu down.
//  * FSMenu.animFade is an alpha fading animation using tranparency.
//  * FSMenu.animClipDown is a "blind" animation similar to 'Swipe'.

	//listMenu.animations[listMenu.animations.length] = FSMenu.animFade;
	listMenu.animations[listMenu.animations.length] = FSMenu.animSwipeDown;
}
Event.observe(window,'load',new Function('listMenu.activateMenu("navigation",arrow)'));

// Login - logout functionality
// ----------------------------------------------

checkForCookie = function()
{
	if ((document.getElementById("txtLoginUsername")!=null)&&(document.getElementById("txtLoginPassword")!=null))
	{
		var a = readCookie('a');
		var b = readCookie('b');
		if (a!=null)
		{
			if (b!=null)
			{
				$("txtLoginUsername").value = readCookie('a');
				$("txtLoginPassword").value = readCookie('b');
				$("chkAutoLogin").checked = "true";
			}
		}
	}	
}

loginUserEnter = function(event,ourform)
{
	switch (BrowserDetect.browser)
	{
	case "Explorer":
	if (window.event && window.event.keyCode == 13)
	{
		loginUser();
	}
	else
	{
		return true;
	}
	break
	
	default:
	if (event && event.which == 13)
	{
		loginUser();
	}
	else
	{
		return true;
	}
	break
	}
}

loginUser = function()
{
	var username = getControlValue('txtLoginUsername');
	var password = getControlValue('txtLoginPassword');

	if (username=="username")
	{
		setControlErrorMessage('txtLoginPassword','Please enter your details');
	}
	else
	{
		resetControlErrorMessage('txtLoginPassword','')
		showFeedback('loginActionContainer');
		eng_login.loginUser('txtLoginUsername', username, 'txtLoginPassword', password, callback_loginUser);
	}
}

callback_loginUser = function(res)
{
	if (res.error != null)
	{
		alert(res.error);
	};
	
	var results = res.value.Tables[0];
	if (results.Rows[0].result == "True")
	{
		if (document.getElementById("chkAutoLogin").checked)
		{
			newCookie('a', document.getElementById("txtLoginUsername").value, 0)
			newCookie('b', document.getElementById("txtLoginPassword").value, 0)
		}
		else
		{
			eraseCookie('a');
			eraseCookie('b');
		}
		var controls = res.value.Tables[1];
		for (var i=0; i<controls.Rows.length; i++)
		{
			clearInputField(controls.Rows[i].controlID);
			resetControlErrorMessage(controls.Rows[i].controlID,'');
		}
		switch (results.Rows[0].errMessage)
		{
			case "valid":
			feedbackValid('Checking your profile&#8230;','Logging you in&#8230;');
			window.setTimeout("hideLoginUser();",4000);
			break
		}
	}
	else
	{
		var controls = res.value.Tables[1];
		switch (results.Rows[0].errMessage)
		{
			case "nomatch":
			feedbackInvalid('loginActionContainer');
			window.setTimeout(function(){processValidationResponse(controls)}, 2001);
			window.setTimeout("setControlErrorMessage('txtLoginPassword','Please check your username/password');",2002);
				
			case "invalid":
			feedbackInvalid('loginActionContainer');
			window.setTimeout(function(){processValidationResponse(controls)}, 2001);
			break
		}
	}
}

hideLoginUser = function()
{
	cleanupFeedback('loginActionContainer');
	window.location.reload();
}

logoutUser = function()
{
	eng_login.logout(callback_logoutUser);
}

callback_logoutUser = function()
{
	window.location = "/logged-out/";
}

// Login help
// ----------------------------------------------
getEmailQuestion = function()
{
	var email = getControlValue('txtEmailPasswordStep1');
	setSpanValue('confirmSuccessEmail', email)
	
	showFeedback('passwordStep1ActionContainer');
	eng_members.getSecQues('txtEmailPasswordStep1', email, callback_getEmailQuestion);
}

callback_getEmailQuestion = function(res)
{
	if (res.error!=null)
	{
		alert(res.error)
	};
	
	var results = res.value.Tables[0];
	if (results.Rows[0].result == "True")
	{
		var controls = res.value.Tables[1];
		for (var i=0; i<controls.Rows.length; i++)
		{
			clearInputField(controls.Rows[i].controlID);
			resetControlErrorMessage(controls.Rows[i].controlID,'');
		}
		var vals = results.Rows[0].errMessage.split("|");
		switch (vals[0])
		{
			case "valid":
			feedbackValid('Looking it up&#8230;','Got it!');
			setSpanValue('emailQuestion', vals[1])
			window.setTimeout("showPasswordQuestion();",4000);
			break
		}
	}
	else
	{
		var controls = res.value.Tables[1];
		switch (results.Rows[0].errMessage)
		{
			case "invalid":
			feedbackInvalid('passwordStep1ActionContainer');
			window.setTimeout(function(){processValidationResponse(controls)}, 2001);
			break
		}
	}
}

showPasswordQuestion = function()
{
	showPasswordRecoveryStep(2);
	cleanupFeedback('passwordStep1ActionContainer');
}

checkEmailQuestion = function()
{
	var answer = getControlValue('txtSecurityAnswerReminder');
	showFeedback('passwordStep2ActionContainer');
	eng_members.checkSecQues('txtSecurityAnswerReminder', answer, callback_checkEmailQuestion);
}

callback_checkEmailQuestion = function(res)
{
	if (res.error!=null)
	{
		alert(res.error)
	};
	var results = res.value.Tables[0];
	if (results.Rows[0].result == "True")
	{
		var controls = res.value.Tables[1];
		for (var i=0; i<controls.Rows.length; i++)
		{
			clearInputField(controls.Rows[i].controlID);
			resetControlErrorMessage(controls.Rows[i].controlID,'');
		}
		switch (results.Rows[0].errMessage)
		{
			case "valid":
			feedbackValid('Sending you mail&#8230;','Done!');	
			window.setTimeout("showPasswordComplete();",4000);
			break
		}
	}
	else
	{
		var controls = res.value.Tables[1];
		switch (results.Rows[0].errMessage)
		{
			case "invalid":
				feedbackInvalid('passwordStep2ActionContainer');
				window.setTimeout(function(){processValidationResponse(controls)}, 2001);
			break
			
			case "incorrect":
				feedbackInvalid('passwordStep2ActionContainer');
				window.setTimeout(function(){processValidationResponse(controls)}, 2001);
			break

		}
	}
}

showPasswordComplete = function()
{
	showPasswordRecoveryStep(3);
	cleanupFeedback('passwordStep2ActionContainer');
}

closePasswordModal = function()
{
	showPasswordRecoveryStep(1);
}

showPasswordRecoveryStep = function(intId)
{
	new Effect.DropOut('passwordRecoveryStep' + (intId - 1));
	new Effect.Appear('passwordRecoveryStep' + intId);
}

newCookie = function(name,value,days)
{
	var days = 10;   // the number at the left reflects the number of days for the cookie to last
	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=/";
}
	
readCookie = function(name)
{
	var nameSG = name + "=";
	var nuller = '';
	if (document.cookie.indexOf(nameSG) == -1)
	return nuller;

	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(nameSG) == 0) return c.substring(nameSG.length,c.length);
	}
	return null;
}

eraseCookie = function(name)
{
	newCookie(name,"",1);
}

toMem = function(a)
{
    newCookie('theName', document.form.name.value);     // add a new cookie as shown at left for every
    newCookie('theEmail', document.form.email.value);   // field you wish to have the script remember
}

delMem = function(a)
{
	eraseCookie('theName');          // make sure to add the eraseCookie function for every field
	eraseCookie('theEmail');
	
	document.form.name.value = '';   // add a line for every field
	document.form.email.value = '';
}

remCookie = function()
{
	document.form.name.value = readCookie("theName");
	document.form.email.value = readCookie("theEmail");
}

// Operations handling
// ----------------------------------------------
showFeedback = function(actionContainerID, message)
{
	if (message==null)
	{
		message = "verifying...";
	}
	var div = document.createElement("div");
	//div.className = "feedback-processing";
	div.className = "in-progress";
	//div.innerHTML = "Verifying&#8230;";
	div.id = "submitFeedback";
	div.style.display = "none";
	
	var imgProc = document.createElement("img")
	imgProc.src = "/images/indicators/default.gif";
	imgProc.alt = "";
	imgProc.id = "processorImage";
	
	
	var divProc = document.createElement("div")
	divProc.className = "indicator";
	
	divProc.appendChild(imgProc)
	
	var spnText = document.createElement("span")
	spnText.id = "plain-text-message";
	spnText.innerHTML = message + "&#8230;";
	
	div.appendChild(divProc)
	div.appendChild(spnText)
	
	//alert(actionContainerID);
	$(actionContainerID).appendChild(div);
	
	var buttons;
	switch (BrowserDetect.browser)
	{
		case "Safari":
			buttons = $(actionContainerID).childNodes[1].id
		break
		
		case "Opera":
			buttons = $(actionContainerID).childNodes[1].id
		break
		
		case "Firefox":
			buttons = $(actionContainerID).childNodes[1].id
		break
		
		default:
			buttons = $(actionContainerID).childNodes[0].id
		break
	}
	
	Effect.Fade(buttons,
	{
		duration: 0.4,
		afterFinish:function()
		{
			Effect.Appear('submitFeedback',
			{
				duration: 0.4
			});
		}
	});
}

updateFeedbackMessage = function(message)
{
	$("plain-text-message").innerHTML = message + "&#8230;";
}

setFeedbackComplete = function(message)
{
	$("submitFeedback").className = 'process-complete';
	$("processorImage").src = "/images/indicators/complete.jpg";
	$("plain-text-message").innerHTML = message;
}

setFeedbackFailed = function()
{
	$("submitFeedback").className = 'in-progress error';
	$("processorImage").src = "/images/lib/pxTransparent.gif";
	$("plain-text-message").innerHTML = 'Failed';
	
	window.setTimeout("scrollToError()",2005);
	
}

scrollToError = function()
{
var errs = document.getElementsByTagName("input")
	
	for (var i = 0;i<errs.length;i++)
		{
			if (errs[i].type=="text")
				{
			
				if (errs[i].className=="textfield error")
					{
					
					new Effect.ScrollTo(errs[i]);
					break;
					}	
				}
			
		}
}

restoreButtons = function(actionContainerID)
{
	//hide processor feedback and restore buttons
	var buttons;
	switch (BrowserDetect.browser)
	{
		case "Safari":
			buttons = $(actionContainerID).childNodes[1].id
		break
		
		case "Firefox":
			buttons = $(actionContainerID).childNodes[1].id
		break
		
		default:
			buttons = $(actionContainerID).childNodes[0].id
		break
	}
	Effect.Fade('submitFeedback',
	{
		duration: 0.4,
		afterFinish:function()
		{
			Effect.Appear(buttons,
			{
				duration: 0.4
			});
			
		}
	});
	
	window.setTimeout(function()
	{
		removeFeedback(actionContainerID)
	},1600);
}

removeFeedback = function(selectorID)
{
	var ac = $(selectorID);
	var sf = $("submitFeedback");
	ac.removeChild(sf);
}
				
cleanupFeedback = function(selectorID)
{
	window.setTimeout(function()
	{
		cleanupFeedbackInner(selectorID)
	},1000);	
}

cleanupFeedbackInner = function(selectorID)
{
	removeFeedback(selectorID);
	var selectorChildID;

	switch (BrowserDetect.browser)
	{
		case "Safari":
			selectorChildID = $(selectorID).childNodes[1].id
		break
		
		case "Firefox":
			selectorChildID = $(selectorID).childNodes[1].id
		break
		
		default:
			selectorChildID = $(selectorID).childNodes[0].id
		break
	}
	
	Effect.Appear(selectorChildID,
	{
		duration: 0
	});
}

feedbackValid = function(message1, message2)
{
	window.setTimeout(function(){updateFeedbackMessage(message1)}, 2000);
	window.setTimeout(function(){setFeedbackComplete(message2)}, 3000);
}

feedbackInvalid = function(buttonContainerID)
{
	window.setTimeout(function(){setFeedbackFailed()}, 1000);			
	window.setTimeout(function(){restoreButtons(buttonContainerID)}, 2000);
}


// Attach functions to window onload
// ----------------------------------------------
//addEventToObject(window,'onload',showAdvertising);
addEventToObject(window,'onload',scanForFormElements);
addEventToObject(window,'onload',showSearch);
addEventToObject(window,'onload',textfield_keywordSearch.init);
addEventToObject(window,'onload',checkForCookie);
addEventToObject(window,'onload',smartUsername.init);
addEventToObject(window,'onload',smartPassword.init);
addEventToObject(window,'onload',scanForExternalLinks);
addEventToObject(window,'onload',preLoadInterfaceImages);