//WIP 11-22-07
//WIP 1-9-07
//WIP 3-2-07

function trim(str)
{
	str = str.replace(/^\s*|\s*$/g,"");
	return str;
}

function fixId(id)
{
	return id.replace(/:/g,"_");
}

function isValidEmail(str)
{
	var filter  = /^([A-Za-z0-9._%-])+@([A-Za-z0-9-]+\.)+[A-Za-z]{2,6}/;
	
	return filter.test(str);	
	//return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

function isValidPassword(str)
{
	var filter  = /^[A-Za-z]([A-Za-z0-9]){5,20}/;
	
	return filter.test(str);		
}

function getElement(id)
{
	if (document.getElementById)
		return document.getElementById(fixId(id));
	else if (document.all)
		return document.all[fixId(id)];
	else if (document.layers)
		return document.layers[fixId(id)];
	else
		return null;
}

function isValid_Newsletter(id)
{
	var inputField;
	var bIsValid=true;

	inputField=getElement(fixId(id));

	if(inputField!=null)
	{
		if(trim(inputField.value)=="" || isValidEmail(inputField.value)==false)
		{
			alert("Please enter a valid email address.");
			bIsValid=false;
			inputField.focus();	
		}
	}
	
	return bIsValid;
}

function MakeDefaultButton(event, defaultButton, postBackScript)
{
	var button;
	
	button=getElement(fixId(defaultButton));
	
	if(button!=null)
	{
		if(event.which || event.keyCode)
		{
			if ((event.which == 13) || (event.keyCode == 13))
			{
				if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) 
				{
					button.click();
					return false;
				}
				else
				{
					if(postBackScript!=null && postBackScript!="")
					{	
						eval(postBackScript);
						return false;
					}
				}
			}
		}
	} 

	return true; 

}

function MakeDefaultButton_B(event, defaultButton, customValidator, postBackScript)
{
	var button;
	
	button=getElement(fixId(defaultButton));
	
	if(button!=null)
	{
		if(event.which || event.keyCode)
		{
			if ((event.which == 13) || (event.keyCode == 13))
			{
				if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) 
				{
					button.click();
					return false;
				}
				else
				{
				
					if (typeof(Page_ClientValidate) == 'function')
					{ 
						if (Page_ClientValidate() == false)
						{ return false; }
					}
		
					if (typeof(customValidator) == 'function')
					{ 
						if (customValidator() == false)
						{ return false; }
					}
					
					if(postBackScript!=null && postBackScript!="")
					{	
						eval(postBackScript);
						return false;
					}
				}
			}
		}
	} 

	return true; 

}


function SetSafeButton(id, postBackScript)
{
	var button;
	
	button=getElement(fixId(id));
	
	if(button!=null)
	{
		if (typeof(Page_ClientValidate) == 'function')
		{ 
			if (Page_ClientValidate() == false)
			{ return false; }
		}
		
		if(postBackScript!=null && postBackScript!="")
		{
			button.disabled = true;
			eval(postBackScript);
		}
	}
	
	return true;
}

function SetSafeButton_B(id, customValidator, postBackScript)
{
	var button;
	
	button=getElement(fixId(id));
	
	if(button!=null)
	{
		if (typeof(Page_ClientValidate) == 'function')
		{ 
			if (Page_ClientValidate() == false)
			{ return false; }
		}
		
		if (typeof(customValidator) == 'function')
		{ 
			if (customValidator() == false)
			{ return false; }
		}

		if(postBackScript!=null && postBackScript!="")
		{
			button.disabled = true;
			eval(postBackScript);
		}
	}
	
	return true;
}

function SetSafeButtons(id, postBackScript)
{
	var objFrm=document.Form1;
	var button;
	
	button=getElement(fixId(id));
	
	if(button!=null)
	{
		if (typeof(Page_ClientValidate) == 'function')
		{ 
			if (Page_ClientValidate() == false)
			{ return false; }
		}
		
		if(postBackScript!=null && postBackScript!="")
		{
			for(var i=0;i<=objFrm.elements.length-1;i++)
			{
				if(objFrm.elements[i].type!=null)
				{
					if((objFrm.elements[i].type == "submit") || (objFrm.elements[i].type == "button"))
						objFrm.elements[i].disabled = true;
				}
			}
			
			eval(postBackScript);
		}
	}
	
	return true;
}

function SetSafeButtons_B(id, customValidator, postBackScript)
{
	var objFrm=document.Form1;
	var button;
	
	button=getElement(fixId(id));
	
	if(button!=null)
	{
		if (typeof(Page_ClientValidate) == 'function')
		{ 
			if (Page_ClientValidate() == false)
			{ return false; }
		}
		
		if (typeof(customValidator) == 'function')
		{ 
			if (customValidator() == false)
			{ return false; }
		}

		if(postBackScript!=null && postBackScript!="")
		{
			for(var i=0;i<=objFrm.elements.length-1;i++)
			{
				if(objFrm.elements[i].type!=null)
				{
					if((objFrm.elements[i].type == "submit") || (objFrm.elements[i].type == "button"))
						objFrm.elements[i].disabled = true;
				}
			}
			
			eval(postBackScript);
		}
	}
	
	return true;
}

function ConfirmLogOut()
{
	var bResponse=confirm("Are you sure you want to log out?");

	return bResponse;
}

function encodeHtml(htmlText)
{
     return htmlText.replace(/&/gi, '&amp;').replace(/\"/gi, '&quot;').replace(/</gi, '&lt;').replace(/>/gi, '&gt;');
}