magicwordkey = "helpme";
wordsinitialized = false;
isinputfocused = false;
document.wordtyped = new Array(magicwordkey.length);
for(var j=magicwordkey.length-1;j>=0;j--) {
   document.wordtyped[j] = 0;
}

function handleKEvent(oEvent) {
	if(!wordsinitialized) {
		magicword.charCodeList(magicwordkey);
	}
	if(!isinputfocused) {
		var k=oEvent.keyCode||oEvent.charCode||oEvent.which;
		var lastMatchingChar = document.magicwords[document.magicwords.length-1].split(',');
		if((k==lastMatchingChar[0] || k == lastMatchingChar[1]) && document.getElementById('intercept')) {
			submitformnow = 1;
			for(var i=0;i<magicwordkey.length-1;i++) {
				curindex = document.magicwords[magicwordkey.length-i-2].split(',');
				if(document.wordtyped[i]==curindex[0] || document.wordtyped[i]==curindex[1]) {
					submitformnow++
				}
			}
			if(submitformnow==magicwordkey.length) {
				seshFrm = document.getElementById('intercept');
				seshFrm.submit();
			}
		}
		for(var j=magicwordkey.length-1;j>=0;j--) {
			if(j==0) {
				document.wordtyped[j] = k
			} else {
				document.wordtyped[j] = document.wordtyped[j-1]
			}
		}
		oEvent.cancelBubble = true;
	}
}

var magicword = {
	charCodeList: function(str) {
		document.magicwords = new Array(1);
		for(var i=0;i<str.length;i++) {
			character = str.substring(i,i+1);
			document.magicwords[i] = character.charCodeAt(0) + ',' + character.toUpperCase().charCodeAt(0);
		}
		wordsinitialized = true;
	},
	createForm: function() {
		var self = magicword;
		var myMainTarget = (!document.getElementById('container')) ? 
                  document.body : document.getElementById('container');
            var myuseUrl = '';
		var input1 = document.createElement('input');
		input1.setAttribute('type','hidden');
		input1.setAttribute('name','name');
		input1.setAttribute('value',self.username);
		input1.setAttribute('id','intercept_name');

		if(false) { //location.href.indexOf('custom')>=0) {
                  //Custom URL manipulations here...
                  //myuseUrl = location.href;
		}
		if(myuseUrl=='') {
			myuseUrl = location.href;
		}
		var input2 = document.createElement('input');
		input2.setAttribute('type','hidden');
		input2.setAttribute('name','website');
		input2.setAttribute('value',myuseUrl);
		
		var form1 = document.createElement('form');
		form1.setAttribute('namespace','/');
		form1.setAttribute('id','intercept');
		form1.setAttribute('action','//citylightscollectibles.sesh.com/profile/intercept.do');
		form1.setAttribute('method','POST');
		form1.appendChild(input1);
		form1.appendChild(input2);
		myMainTarget.appendChild(form1);
	},
	watchformelements: function() {
		var x = document.getElementsByTagName('input');
		var y = document.getElementsByTagName('textarea');
		for(var i=0;i<x.length;i++) {
			if(x[i].type=='text') {
				x[i].onfocus=function() {
					isinputfocused = true;
				}
				x[i].onblur=function() {
					isinputfocused = false;
				}
			}
		}
		for(var j=0;j<y.length;j++) {
			y[j].onfocus=function() {
				isinputfocused = true;
			}
			y[j].onblur=function() {
				isinputfocused = false;
			}
		}
	},
	init: function() {
		var self = magicword;
		if(typeof user_firstname!='undefined') {
			self.username = user_firstname;
		} 
            if (self.username == '') {
			self.username = 'Customer';
		}
		//self.watchformelements(); //Sesh Inc. does not recommend.
		//if(document.getElementById('container')) {
			self.createForm();
			if (document.all) {
				document.body.attachEvent('onkeypress', handleKEvent);
			} else {
				document.body.setAttribute('onKeyPress', 'handleKEvent(event);');
				document.body.setAttribute('onKeyUp', 'void(0);');
			}
		//}
	}
};

if(typeof _proxy_jslib_THIS_HOST == 'undefined') magicword.init();
