	function clearField(strFieldName, strString) {
		if (strFieldName.value == strString) {
			strFieldName.value = "";
		}
	}
	function fillField(strFieldName, strString) {
		if (strFieldName.value == "") {
			strFieldName.value = strString;
		}
	}
	function openWindow(sUrl, sName, iWidth, iHeight, bResizable, bScrollbars, bStatus) { 
	        var iLeft = parseInt((screen.availWidth/2)-(iWidth/2)); 
	        var iTop = parseInt((screen.availHeight/2)-(iHeight/2)); 
	        var iRandom = Math.floor(Math.random()*99); 
	        
	        var oWindow = window.open (sUrl, sName + iRandom, 'toolbar=0,location=0,menubar=0,directories=0,scrollbars='+ bScrollbars +',status='+ bStatus +',resizable='+ bResizable +',Width='+ iWidth +',Height='+ iHeight +',left='+ iLeft +',top='+ iTop +',screenX='+ iLeft +',screenY='+ iTop +'');
	
	        oWindow.focus(); 
	} 
	function openStaticWindow(o_url, o_name, o_width, o_height) {
		var o_left = (screen.availWidth/2)-(o_width/2);
		var o_top = (screen.availHeight/2)-(o_height/2);
		window.open (o_url, o_name, 'toolbar=0,location=0,menubar=0,directories=0,scrollbars=0,status=0,resizable=0,Width='+ o_width +',Height='+ o_height +',left='+ o_left +',top='+ o_top +',screenX='+ o_left +',screenY='+ o_top +'');
	}
	function FormHandler (formName, layername) 
	{
		if (browser.isNS) 
		{ 
			if (typeof (layername) != 'undefined') 
				lay = "document." + layername + ".";
			else 
				lay = "";
			this.obj = eval (lay +"document." + formName);
		} 
		else 
		{ 
			this.obj = eval("document." + formName);
		}
		
		this.fieldname = new Array ();
		this.errormessage = new Array ()
		this.fieldtype = new Array ();
		this.minlength = new Array ();
		
		this.add = FormHandlerAdd;
		this.check = FormHandlerCheck;
		this.error = FormHandlerError;
		
		this.TEXT     = "text";
		this.NUMBER   = "number";
		this.EMAIL    = "email";
		this.CHECKBOX = "checkbox";
		this.RADIO    = "radio";
		this.SELECT   = "select";
		this.PASSWORD = "password";
	}
	function FormHandlerAdd (fieldname, errormessage, minlength, fieldtype) 
	{
		current = this.fieldname.length;
		this.fieldname[current] = fieldname;
		this.errormessage[current] = errormessage;
		
		if (typeof (fieldtype) != 'undefined')
			this.fieldtype[current] = fieldtype;
		else
			this.fieldtype[current] = FormHandler.TEXT;
		
		if (typeof (minlength) != 'undefined') 
			this.minlength[current] = minlength;
		else 
			this.minlength[current] = 0;
	}
	function FormHandlerCheck() 
	{
		for (var i = 0; i < this.fieldname.length; ++i) 
		{
			currentField = eval ("this.obj." + this.fieldname[i]);
			
			if (currentField.value != null)
				currentFieldLC = currentField.value.toLowerCase ();
				
			if (this.fieldtype[i] == this.TEXT)
			{
				if (currentField.value.length < this.minlength[i])
					return this.error (i);
			}
			else if (this.fieldtype[i] == this.NUMBER)
			{
				if (currentField.value.length < this.minlength[i])
					return this.error (i);
				if (currentField.value.match (/[\d\,\.\-]+/) != currentField.value)
					return this.error (i);
			}
			else if (this.fieldtype[i] == this.EMAIL)
			{
				if (currentField.value.length < this.minlength[i])
					return this.error (i)
				if (currentFieldLC != currentFieldLC.match (/[\w-\.]+@([\w\-_]+\.)*[a-z]{2}[a-z]?[a-z]?/gi))
					return this.error (i);
			}
			else if (this.fieldtype[i] == this.CHECKBOX)
			{
				if (!currentField.checked)
					return this.error(i);
			}
			else if (this.fieldtype[i] == this.RADIO)
			{
				var isChecked = false;
				for (var r=0; r < currentField.length; r++)
				{
					if (currentField[r].checked)
						isChecked =true;
				}
				if(!isChecked)
					return this.error (i);
			}
			else if (this.fieldtype[i] == this.SELECT)
			{
				if (currentField.options[currentField.selectedIndex].value == -1)
					return this.error (i);
			}
			else if (this.fieldtype[i] == this.PASSWORD)
			{
				passwordField = eval ("this.obj." + this.fieldname[i] + "2");
				
				if (currentField.value.length < this.minlength[i]
					||  currentField.value != passwordField.value)
				{
					return this.error (i);
				}
			}
			
		}
		return true
	}
	function FormHandlerError(id) 
	{
		alert (this.errormessage[id]);
		currentField = eval("this.obj." + this.fieldname[id]);
		if (this.fieldtype[id] != this.RADIO)
			currentField.focus ();
		return false;
	}
	function urlMenu(that) {
		theURL = that.options[that.selectedIndex].value; 
	
		if (theURL) {
			window.location = theURL;
		}
	}
	function toggleDiv(divid) {
		if (document.all) {
			targetDiv = eval("document.all."+divid);
			if (targetDiv.style.display != "block") {
				targetDiv.style.display = "block";
			} else {
				targetDiv.style.display = "none";
			}
		}
	}
	function replaceAll( str, from, to ) {
	    var idx = str.indexOf( from );
		
	    while ( idx > -1 ) {
	        str = str.replace( from, to ); 
	        idx = str.indexOf( from );
	    }
		
	    return str;
	}
	function fUnEscape(sVar){
		return unescape(replaceAll(sVar, '+', ' '));
	}
	function addNote(iID, sItem, sNext, sOldNote) {
		var sNote = prompt('Add note for: '+ sItem, fUnEscape(sOldNote));
		if (sNote) {
			document.location = '/stuff/shop_addNote_resp.asp?function=addNote&id='+ iID +'&note='+ escape(sNote) +'&next='+ sNext;
		}
	}
	function getQueryStringValue(sKey){ 
		var queryString = location.search;
		var regExp = new RegExp( "[?&]" + sKey + "=([^&]*)", "gi" );
		var resultArray = queryString.match( regExp );
		if( resultArray != null ){
			return resultArray[0].substring( sKey.length + 2, resultArray[0].length );
		} else {
			return "";
		} 
	}
	if (getQueryStringValue("alert")) {
		alert(getQueryStringValue("alert"));
	}
	function confirmDelete(s) {
		return window.confirm(s);
	}
	// Open new windows
	function popUp(sUrl, sType) {
		switch(sType) {
			case "portrait":
				openWindow(sUrl, "landscape", 423, 610, 0, 0, 0, 0)
				break;
	
			case "landscape":
				openWindow(sUrl, "portrait", 770, 530, 0, 0, 0, 0);
				break;
	
			case "change_your_life":
				openWindow(sUrl, "change_your_life", 598, 431, 0, 0, 0, 0)
				break;
	
			case "old_diary":
				openWindow(sUrl, "old_diary", 415, 600, 0, 0, 0, 0)
				break;
	
			case "tcs":
				openWindow(sUrl, "tcs", 300, 200, 0, 0, 0, 0)
				break;
	
			case "secpay":
				openWindow(sUrl, "secpay", 600, 770, 1, 0, 1, 1)
				break;
	
			case "thawte":
				openWindow(sUrl, "secpay", 500, 560, 0, 0, 1, 0)
				break;

			default:
				openWindow(sUrl, "popup", 640, 480, 0, 0, 0, 0)
				break;
		}
	}
	function openWindow(sUrl, sName, iWidth, iHeight, bResizable, bScrollbars, bStatus, bLocation) {
		var iLeft = parseInt((screen.availWidth/2)-(iWidth/2));
		var iTop = parseInt((screen.availHeight/2)-(iHeight/2));
		var iRandom = Math.floor(Math.random()*99);
		
		var oWindow = window.open (sUrl, sName + iRandom, 'toolbar='+ bLocation +',location='+ bLocation +',menubar=0,directories=0,scrollbars='+ bScrollbars +',status='+ bStatus +',resizable='+ bResizable +',Width='+ iWidth +',Height='+ iHeight +',left='+ iLeft +',top='+ iTop +',screenX='+ iLeft +',screenY='+ iTop +'');
		oWindow.focus();
	}
	
	//Registration functions
	function checkUser() {
		if (fh.check()){
			if (browser.isSafari){
				document.getElementById("register").submit();
			} else {
				// Send off the proposed softid for server-side checking. The check will return a javascript call to functions below
				var sParam = '/content/check_user.asp?email=' + document.getElementById("email").value + '&username=' + document.getElementById("user_name").value;
				document.getElementById("check_user").src = sParam;
			}
		}
	}
	function allCool() {
		// All is well, let's submit the form!
		document.getElementById("register").submit();
	}
	function bothExists() {
		// This softid already exists.
		alert("Sorry, both username and email address is already in use.")
		document.getElementById("user_name").select();
	}
	function usernameExists() {
		// This softid already exists.
		alert("Sorry, that username is already in use.")
		document.getElementById("user_name").select();
	}
	function emailExists() {
		// This softid already exists.
		alert("Sorry, that email address is already in use.")
		document.getElementById("email").select();
	}
