jQuery(document).ready(function(){
	// Ghost text in search form field
	var search_box = jQuery(":text.search");
	var search_text = "Search";
	if(search_box.attr("value").length == 0) {
		search_box.attr("value", search_text);
		search_box.css("color","#ccc");
	}
	else if (search_box.attr("value") != search_text){
		search_box.css("color","#666");
	}
	search_box.blur(function(){
		if(this.value.length == 0) {
			this.value = search_text;
			jQuery(this).css("color","#ccc");
		}
	});
	search_box.click(function(){
		if(this.value == search_text) {
			this.value = "";
			jQuery(this).css("color","#666");
		}
	});
	//
});

function changeEmail(strFieldName,strFieldValue)
{
	eval("if(document." + strFieldName + ".value.replace(/^\s*/, '').replace(/\s*$/, '') == strFieldValue)")
		{
		  eval("document." + strFieldName + ".value = '';")
		}
}


function checkEmail(obj)
{
	if (obj.value == null || obj.value == "")
		{ 
			return true; 
		} 
	var em = obj.value
	var re = new RegExp();
	re = /.+@.+\..+/
	if (em != "") 
		{
			if (!(re.test(em))) 
				{
					return false;
				}
		return true;
		}
}

function ValidateGlossaryTerm()
{
	if(document.getElementById('_gname').value.replace(/^\s*/, '').replace(/\s*$/, '') == "")
		{
			alert('Please enter your name. Click OK to try again. Thanks.');
			document.getElementById('_gname').focus();
			return false;
		}
	if(document.getElementById('_gemail').value.replace(/^\s*/, '').replace(/\s*$/, '') == "")
		{
			alert('Please enter your email address. Click OK to try again. Thanks.');
			document.getElementById('_gemail').focus();
			return false;
		}
	else
		{
			if(!checkEmail(document.getElementById("_gemail")))
			{
				alert('Whups!  You forgot to enter your correct email address. Click OK to try again. Thanks.');					
				document.getElementById("_gemail").select();
				return false;
			}
		}
	return true
}


function ValidateNews()
{
	if(document.getElementById('_newsEmail').value.replace(/^\s*/, '').replace(/\s*$/, '') == "")
		{
			alert('Please enter your email address. Click OK to try again. Thanks.');
			document.getElementById('_newsEmail').focus();
			return false;
		}
	else
		{
			if(!checkEmail(document.getElementById("_newsEmail")))
			{
				alert('Whups!  You forgot to enter your correct email address. Click OK to try again. Thanks.');					
				document.getElementById("_newsEmail").select();
				return false;
			}
		}
	return true
}

function ValidateContact()
{
	if(document.getElementById('_CName').value.replace(/^\s*/, '').replace(/\s*$/, '') == "")
		{
			alert('Please enter your name. Click OK to try again. Thanks.');
			document.getElementById('_CName').focus();
			return false;
		}
	if(document.getElementById('_CEmail').value.replace(/^\s*/, '').replace(/\s*$/, '') == "")
		{
			alert('Please enter your email address. Click OK to try again. Thanks.');
			document.getElementById('_CEmail').focus();
			return false;
		}
	else
		{
			if(!checkEmail(document.getElementById("_CEmail")))
			{
				alert('Whups!  You forgot to enter your correct email address. Click OK to try again. Thanks.');					
				document.getElementById("_CEmail").select();
				return false;
			}
		}
	return true;
}

function ValidateGlossary()
{
	if(document.getElementById('_glossaryEmail').value.replace(/^\s*/, '').replace(/\s*$/, '') == "")
		{
			alert('Please enter your email address. Click OK to try again. Thanks.');
			document.getElementById('_glossaryEmail').focus();
			return false;
		}
	else
		{
			if(!checkEmail(document.getElementById("_glossaryEmail")))
			{
				alert('Whups!  You forgot to enter your correct email address. Click OK to try again. Thanks.');					
				document.getElementById("_glossaryEmail").select();
				return false;
			}
		}
	return true
}


function ValidateSignup()
{
	if(document.getElementById('_emailResults').value.replace(/^\s*/, '').replace(/\s*$/, '') == "")
		{
			alert('Please enter your email address. Click OK to try again. Thanks.');
			document.getElementById('_emailResults').focus();
			return false;
		}
	else
		{
			if(!checkEmail(document.getElementById("_emailResults")))
			{
				alert('Whups!  You forgot to enter your correct email address. Click OK to try again. Thanks.');					
				document.getElementById("_emailResults").select();
				return false;
			}
		}
	return true
}		
