var RegisterPage =
{ 
	submitted : 0,
	ValidationElement : new Array(),
	CorrectValidatedElement : new Array(),
	TextBoxKeypressEvent : function(id, e)
	{
		var bAdd = false;
		if(document.all)
		{
			e = window.event;
		}
		if(document.all)
		{
			if(e.keyCode >= 32 && e.keyCode <= 126)
			{
				bAdd = true;
			}
		}
		else
		{
			if(e.which >= 32 && e.which <= 126)
			{
				bAdd = true;
			}
		}
		if(bAdd)
		{
			if(!RegisterPage.CheckElementStacked(id))
			{
				this.ValidationElement[this.ValidationElement.length] = id;
			}
		}
		RegisterPage.Validation(id, false);
		if(id == "password")
		{
			RegisterPage.Validation("passwordconfirm", false);
		}
		if(id == "emailaddr")
		{
			RegisterPage.Validation("emailconfirm", false);
		}
	},
	
	CheckElementStacked : function(id)
	{
		var iLoop;
		for(iLoop = 0; iLoop < this.ValidationElement.length; iLoop++)
		{
			if(this.ValidationElement[iLoop] == id)
			{
				return true;
			}
		}
		return false;
	},
	
	CheckElementValidated : function(id)
	{
		var iLoop;
		for(iLoop = 0; iLoop < this.CorrectValidatedElement.length; iLoop++)
		{
			if(this.CorrectValidatedElement[iLoop] == id)
			{
				return true;
			}
		}
		return false;
	},
	
	TextBoxClick : function(id)
	{
		var txts = new Object();
		txts['username'] = "Username";
		txts['password'] = "Password";
		txts['passwordconfirm'] = "Confirm Password";
		txts['emailaddr'] = "Email";
		txts['emailconfirm'] = "Confirm Email";
		var obj = document.getElementById(id);
		if(obj != null)
		{
			if(obj.value.toLowerCase() == txts[id].toLowerCase() && obj.focused == true)
			{
				obj.value = "";
				if(id == 'password' || id == 'passwordconfirm')
				{
					obj = RegisterPage.ChangeInputElement(obj, 'password');
				} 
			}
			else if(obj.value == "" && obj.focused== false)
			{
				obj.value = txts[id];
				if(id == 'password' || id == 'passwordconfirm')
				{
					obj = RegisterPage.ChangeInputElement(obj, 'text');
				} 
			}
			else if(obj.value.toLowerCase() == txts[id].toLowerCase() && obj.focused == false)
			{
				if(id == 'password' || id == 'passwordconfirm')
				{
					obj = RegisterPage.ChangeInputElement(obj, 'text');
				} 
			}
			
			if(id == 'password')
			{
				$("#trConfirmPassword").slideDown();
				if(document.all)
				{
					$("#trConfirmPassword").get(0).style.display = "block";
				}
				else
				{
					$("#trConfirmPassword").get(0).style.display = "table-row";
				}
			}
			
			if(id == 'emailaddr')
			{
				$("#trConfirmEmail").slideDown();
				if(document.all)
				{
					$("#trConfirmEmail").get(0).style.display = "block";
				}
				else
				{
					$("#trConfirmEmail").get(0).style.display = "table-row";
				}
			}
			
			if(obj.focused == true)
			{
				$("#" + "DivHelp_" + id).fadeIn();
			}
			else
			{
				$("#" + "DivHelp_" + id).fadeOut();
			}
			
			if(obj.focused == false)
			{
				RegisterPage.Validation(id, true);
			}
			
		}
	},// Function Ends Here
	
	ChangeInputElement : function(oldObject, oType)
	{
		if(document.all)
		{
			/*var newObject = document.createElement('input');
			newObject.type = oType;
			if(oldObject.size) newObject.size = oldObject.size;
			if(oldObject.value) newObject.value = oldObject.value;
			if(oldObject.name) newObject.name = oldObject.name;
			if(oldObject.id) newObject.id = oldObject.id;
			if(oldObject.className) newObject.className = oldObject.className;
			if(oldObject.focused) newObject.focused = oldObject.focused;
			oldObject.parentNode.replaceChild(newObject,oldObject);
		  	return newObject;*/
		}
		else
		{
			oldObject.type = oType;
		}
		return oldObject;
	},
	
	Validation : function(id, bShowError)
	{
		var obj = document.getElementById(id);
		var nErrorState = 0;
		var objIcon, objRevIcon;
		var emailFilter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if(obj != null)
		{
			switch(id)
			{
				case "username":
					if(obj.value.length < 3 || obj.value.toLowerCase() == "username")
					{
						nErrorState =  RegisterPage.CheckElementStacked(id) ? 1 : 0;
					}
					else
					{
						nErrorState = 2;
					}
					break;	
				case "password":
					if(obj.value.length < 4 || obj.value.toLowerCase() == "password" || obj.value.toLowerCase() == "confirm password")
					{
						nErrorState =  RegisterPage.CheckElementStacked(id) ? 1 : 0;
					}
					else
					{
						nErrorState = 2;
					}
					break;	
				case "passwordconfirm":
					if(obj.value.length < 4 || obj.value.toLowerCase() == "confirm password" || obj.value.toLowerCase() =="password" || obj.value != document.getElementById("password").value)
					{
						nErrorState =  RegisterPage.CheckElementStacked(id) ? 1 : 0;
					}
					else
					{
						nErrorState = 2;
					}
					break;	
				case "emailaddr":
					if(!emailFilter.test(obj.value))
					{
						nErrorState =  RegisterPage.CheckElementStacked(id) ? 1 : 0;
					}
					else
					{
						nErrorState = 2;
					}
					break;	
				case "emailconfirm":
					if(!emailFilter.test(obj.value) || obj.value != document.getElementById("emailaddr").value)
					{
						nErrorState =  RegisterPage.CheckElementStacked(id) ? 1 : 0;
					}
					else
					{
						nErrorState = 2;
					}
					break;		
			}
			//alert(nErrorState);
			if(nErrorState == 1 && (bShowError == true || RegisterPage.CheckElementValidated(id)))
			{
				objIcon = document.getElementById("DivIncorrect_" + id);
				objRevIcon = document.getElementById("DivCorrect_" + id);
				objIcon.style.display = "block";
				objRevIcon.style.display = "none";
			}
			else if (nErrorState == 2)
			{
				objIcon = document.getElementById("DivCorrect_" + id);
				objRevIcon = document.getElementById("DivIncorrect_" + id);
				objIcon.style.display = "block";
				objRevIcon.style.display = "none";
				if(!RegisterPage.CheckElementValidated(id))
				{
					this.CorrectValidatedElement[this.CorrectValidatedElement.length] = id;
				}
			}
		}
	},
	
	HasSubmitted : function()
	{
		if (this.submitted == 0)
		{
			this.submitted = 1;
			return true;
		}
		else
		{
			window.alert ('The posting is pending processing');
			return false;
		}
	},
	
	SetPageHeader : function()
	{
		ContentDisplayJS.EmbedFontByCSS("CategoryTitle", "Casual Contact MF");
		ContentDisplayJS.EmbedFontByCSS("ContentBoxSubHeader", "standard 07_55");
		ContentDisplayJS.EmbedFontByCSS("RegHelpLinks", "standard 07_55");
	},
	
	HelpAccordian : function()
	{
		$(document).ready(function(){
		$('#DivAccordian').hoverAccordion({
			activateitem: '1',
			speed: 'fast'
		});
		$('#DivAccordian').children('li:first').addClass('firstitem');
		$('#DivAccordian').children('li:last').addClass('lastitem');
		});
	},
	
	init : function()
	{
		RegisterPage.SetPageHeader();
		RegisterPage.HelpAccordian();
	}
	
}
