/*
* COPYRIGHT 2011 Jobvite, Inc. All rights reserved. This copyright notice is Copyright Management 
* Information under 17 USC 1202 and is included to protect this work and deter copyright infringement.  
* Removal or alteration of this Copyright Management Information without the express written permission 
* of Jobvite, Inc. is prohibited, and any such unauthorized removal or alteration will be a violation of 
* federal law.
*/
function alertSubmit(id)
{
	if (typeof(Page_BlockSubmit) == 'undefined' || typeof(Page_Validators) == 'undefined')
		return;
	alertClear(id);
	var i;
	var hasRequired = false;
	var found = false;
	for (i = 0; i < Page_Validators.length; i++)
	{
		o = document.getElementById(Page_Validators[i].controltovalidate);
		if (o)
			o.style.backgroundColor = 'white';
	}
	for (i = 0; i < Page_Validators.length; i++)
	{
		if (!Page_Validators[i].isvalid)
		{
			if (!hasRequired)
			{
				if (!found)
				{
					o = document.getElementById(Page_Validators[i].controltovalidate);
					if (o)
						o.focus();
				}
				if (Page_Validators[i].evaluationfunction.toString().indexOf('RequiredFieldValidatorEvaluateIsValid') != -1)
				{
					hasRequired = true;
					o = document.getElementById(Page_Validators[i].controltovalidate);
					if (o)
						o.focus();
				}
				alertMessage(id, Page_Validators[i].errormessage);
				found = true;
			}
			o = document.getElementById(Page_Validators[i].controltovalidate);
			if (o)
				o.style.backgroundColor = '#ffd8d9';
		}
	}
}
function alertMessage(name, s)
{
	var o = document.getElementById(name);
	if (o)
		o.innerHTML = s;
	o = document.getElementById('div' + name);
	if (o)
		o.style.display = 'block';
}
function alertClear(name)
{
	var o = document.getElementById(name);
	if (o)
		o.innerHTML = '';
	o = document.getElementById('div' + name);
	if (o)
		o.style.display = 'none';
}
function alertShow(name)
{
	o = document.getElementById('div' + name);
	if (o)
		o.style.display = 'inline';
}
function alertHide(name)
{
	o = document.getElementById('div' + name);
	if (o)
		o.style.display = 'none';
}
function alertCheckRequiredField(name, id)
{
	var o = document.getElementById(id);
	if (alertTrim(o.value).length == 0)
	{
		alertMessage(name, 'Please fill out missing information.');
		o.style.backgroundColor = '#ffd8d9';
		o.focus();
		return false;
	}
	else
	{
		o.style.backgroundColor = 'White';
		return true;
	}
}
function alertCheckEmailField(name, id)
{
	var o = document.getElementById(id);
	if (!alertEmailValid(alertTrim(o.value)))
	{
		alertMessage(name, 'Must be email address.');
		o.style.backgroundColor = '#ffd8d9';
		o.focus();
		return false;
	}
	else
	{
		o.style.backgroundColor = 'White';
		return true;
	}
}
function alertCheckZipField(name, id)
{
	var o = document.getElementById(id);
	if (!alertZipValid(alertTrim(o.value)))
	{
		alertMessage(name, 'Incorrect zip code.');
		o.style.backgroundColor = '#ffd8d9';
		o.focus();
		return false;
	}
	else
	{
		o.style.backgroundColor = 'White';
		return true;
	}
}
function alertEmailValid(s)
{
	var regex = new RegExp('\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*');
	var matches = regex.exec(s);
	return (matches != null && s == matches[0]);
}
function alertZipValid(s)
{
	var regex = new RegExp('\\d{5}(-\\d{4})?');
	var matches = regex.exec(s);
	return (matches != null && s == matches[0]);
}
function alertTrim(s)
{
	var m = s.match(/^\s*(\S+(\s+\S+)*)\s*$/);
	return (m == null) ? "" : m[1];
}

