function _MatchPage(_pageCode)
{
	var _windowTimer = null;
	var _renderComplete = false;
	this.UpdateFormActions = _tsUpdateFormActions;
	this.PageCode = _pageCode;
	this.WindowTimer = _windowTimer;
	this.RenderComplete = _renderComplete;
	this.FormReplaceVar = "@FORMURL"
	this.MainForm = 'document.matchMainForm';
	this.SubmitForm = _submitForm;
	this.EnsureObjects = _ensureObjects;
	this.BlockEnterKey = false;
	this.recursiveIterations = 0;
	return this;
}

function _onloadEventHandler(args)
{
	if(jsMatchPage)
	{
		jsMatchPage.RenderComplete = true;
		jsMatchPage.EnsureObjects();
		if(!jsMatchPage.MainForm){return;}
		if(jsMatchPage.MainForm.__FORMQUERYSTRING)
		{
			jsMatchPage.UpdateFormActions(jsMatchPage.MainForm.__FORMQUERYSTRING.value);
		}
	}
	window.onkeypress = handleKeyPress;
	window.document.onkeypress = handleKeyPress;					//Netscape 6.x
	window.document.body.onkeypress = handleKeyPress;		//All others
	if(FireOnload)
	{
		FireOnload(args);
	}
}

function _ensureObjects()
{
	if(typeof this.MainForm != 'object'){this.MainForm = eval(this.MainForm);}
}

function _submitForm(linkID)
{
	this.EnsureObjects();
	if(!this.MainForm){return;}
	//var newFormUrl = this.MainForm.action;
	var newFormUrl = this.MainForm.__FORMQUERYSTRING.value;
	var tempArray;
	var currentLinkID;
	var startPoint = -1;
	var endPoint = -1;
	if(linkID.toString().length > 0)
	{
		//This gets the current LID value from the QS.  This is required in case there is a LID from another link (typical)
		//So this handles replacing a dynamic LID value using RegEx
		startPoint = newFormUrl.indexOf("lid=");
		endPoint = newFormUrl.indexOf("&",newFormUrl.indexOf("lid="));
		startPoint = (startPoint == -1) ? 0 : startPoint + 4;
		endPoint = (endPoint == -1) ? newFormUrl.length : endPoint;
		currentLinkID = newFormUrl.substring(startPoint,endPoint);
		//Test the new QS for the existence of the LID param
		if(newFormUrl.indexOf("lid=") > -1)
		{
			//--REMOVED to enable the replacement of the entire url, not just the QS
			//tempArray = newFormUrl.split('?');
			//newFormUrl = tempArray[1];
			//tempArray = null;
			var regExp = eval('/lid=' + currentLinkID + '/');
			newFormUrl = newFormUrl.replace(regExp,"lid=" + linkID.toString());
		}
		else	//No LID
		{
			if(newFormUrl.indexOf("?") > 0)
			{
				//--REMOVED to enable the replacement of the entire url, not just the QS
				//tempArray = newFormUrl.split('?');
				//newFormUrl = tempArray[1];
				//tempArray = null;
				newFormUrl += '&lid=' + linkID.toString();
			}
			else
			{
				newFormUrl = '?lid=' + linkID.toString();
			}
		}
		this.UpdateFormActions(newFormUrl);
	}
	if(this.MainForm.onsubmit != null)
	{
		this.MainForm.onsubmit = null;
	}
	//Inclusion of this line will disconnect .Net's ability to trap the button click events.
	//this.MainForm.submit();
}

function _tsUpdateFormActions(newUrl)
{
	if(this.WindowTimer){window.clearTimeout(this.WindowTimer);}
	if((newUrl == '') || (typeof newUrl== 'undefined') || (newUrl == null)){return false;}
	var tempArray;
	var formTarget;
	var regExp = eval("/" + this.FormReplaceVar + "\\?/");
	var loopCount;
	var useSSL = (newUrl.indexOf("http") > -1) ? true : false;
	with(document)
	{
		if(forms)
		{
			for(loopCount = 0;loopCount < forms.length;loopCount++)
			{
				if(forms[loopCount].__FORMPOSTBACK)		//Ensure that the form we are parsing is the Match main form
				{
					if(useSSL)
					{
						formTarget = forms[loopCount].__FORMPOSTBACK.value + '?';
					}
					else
					{
						tempArray = forms[loopCount].action.split("?");
						formTarget = tempArray[0] + '?';
						tempArray = null;
					}
					forms[loopCount].action = (newUrl.indexOf(this.FormReplaceVar) > -1) ? newUrl.replace(regExp,formTarget) : newUrl;
					//Enable this line to blanket-block the default submit action for all forms
					//forms[loopCount].onsubmit = blockSubmit;
				}
				forms[loopCount].onsubmit = preSubmitActions;
				forms[loopCount].onkeypress = handleKeyPress;
				/*  NOTE: Enable this to *partially* disable the enter key (used to submit forms) on Netscape.
				for (var i = 0; i < forms[loopCount].elements.length;i++)
				{
					forms[loopCount].elements[i].onkeydown = handleKeyPress;
				}
				*/
			}
		}
		else
		{
			if(this.recursiveIterations < 5)
			{
				this.WindowTimer = window.setTimeout('_tsUpdateFormActions("' + newUrl + '");',250);
				this.recursiveIterations++;
			}
		}
	}
	return true;
}

function blockSubmit(){return false;}

function preSubmitActions()
{
	var returnValue = true;
	if(this)
	{
		if(this.action.indexOf("sid") > -1){unloadPopup = false;}
	}
	/*  NOTE: Enable this to *partially* disable the enter key (used to submit forms) on Netscape.  This does not work correctly because of the order of event firing/bubbling in the NS DOM.
	if(jsMatchPage.BlockEnterKey)
	{
		returnValue = false;
	}
	*/
	return returnValue;
}

function handleKeyPress(newEvent)
{
	var isIE = (navigator.appVersion.toLowerCase().indexOf("msie") > -1) ? true : false;
	if(isIE)
	{
		if(event){newEvent = event;}
	}
	jsMatchPage.BlockEnterKey = false;
	if(newEvent != null)
	{
		if(parseInt(newEvent.keyCode) == 13)
		{
			if(isIE)
			{
				newEvent.returnValue = false;
			}
			else
			{
				newEvent.stopPropagation = true;
				newEvent.preventDefault = true;
				newEvent.preventBubble = true;
			}
			jsMatchPage.BlockEnterKey = true;
			newEvent.cancelBubble = true;
			return false;
		}
	}
}

var tourWinHeight = 395;
var tourWinWidth = 715;

function openMatchTour(tourUrl)
{
	var windowFeatures = "height=" + tourWinHeight + ",width=" + tourWinWidth + ",innerHeight=" + tourWinHeight + ",innerWidth=" + tourWinWidth + ",hotkeys=0,location=0,menubar=0,personalbar=0,resizable=0,scrollbars=0,status=0,titlebar=1,toolbar=0";
	if(tourUrl.length > 0)
	{
		window.open(tourUrl,"_matchTour",windowFeatures);
	}
}

window.onerror = null;
