

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);
}

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 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 ConfirmExit(expirydate)
{
	var message;
	
	if(expirydate!=null && expirydate!="")
	{
		message="Are you sure you want to exit the submission process?  If you leave, your submission will be SAVED";
		message+=" automatically and you can RESUME it at a later date. However, be warned that your submission has a";
		message+=" 5-day life cycle within our system and is scheduled to be removed on "+ expirydate +" ET if you have NOT submitted your information.";
	}
	else
	{
		message="Are you sure you want to exit the submission process?  If you leave, your submission will be SAVED";
		message+=" automatically and you can RESUME it at a later date.";
	}
	
	var bResponse=confirm(message);

	return bResponse;

}

function ConfirmLogOut(isSubmissionStepPage,expirydate)
{
	var message;
	
	if(isSubmissionStepPage==true)
	{
		if(expirydate!=null && expirydate!="")
		{
			message="Are you sure you want to log out?  If you leave, your submission will be SAVED";
			message+=" automatically and you can RESUME it at a later date. However, be warned that your submission has a";
			message+=" 5-day life cycle within our system and is scheduled to be removed on "+ expirydate +" ET if you have NOT submitted your information.";
		}
		else
		{
			message="Are you sure you want to log out?  If you leave, your submission will be SAVED";
			message+=" automatically and you can RESUME it at a later date.";
		}
	}
	else
		message="Are you sure you want to log out?";
	
	var bResponse=confirm(message);

	return bResponse;

}

function CheckAll(parentname,ctrlname,checked)
{
	var elements=document.getElementsByTagName("input");
	
	for(var n=0;n<=elements.length-1;n++) 
	{
			e = elements[n];
			
			if (e.type=="checkbox" && e.name.indexOf(parentname)>-1 && e.name.indexOf(ctrlname)>-1)
				e.checked=checked;
	}
}

function encodeHtml(htmlText)
{
     return htmlText.replace(/&/gi, '&amp;').replace(/\"/gi, '&quot;').replace(/</gi, '&lt;').replace(/>/gi, '&gt;');
}

function ConfirmAction(message)
{
	var bResponse=confirm(message);

	return bResponse;
}

function PriceDisplay(price)
{
	if (price.toFixed)
		price=price.toFixed(2);
		
	return price;
}


function GetSelectedRadioValue(parentname,ctrlname)
{
	var elements=document.getElementsByTagName("input");
	var radioValue="";
	
	for(var n=0;n<=elements.length-1;n++) 
	{
			e = elements[n];
			
			if (e.type=="radio" && e.name.indexOf(parentname)>-1 && e.name.indexOf(ctrlname)>-1 && e.checked==true)
				radioValue=e.value;
	}
	
	return radioValue;
}

function SetUniqueSelectedRadio(parentname,ctrlname,obj)
{
	var elements=document.getElementsByTagName("input");
	
	for(var n=0;n<=elements.length-1;n++) 
	{
			e = elements[n];
			
			if (e.type=="radio" && e.name.indexOf(parentname)>-1 && e.name.indexOf(ctrlname)>-1)
				e.checked=false;
	}
	
	if(obj!=null)
		obj.checked=true;
}