function ValidateData() 
{
	//Validate the data that the customer is about to send
							
	//Validate email address
	if (document.forms["theForm"].email.value.indexOf ('@',0) == -1 || document.forms["theForm"].email.value.indexOf ('.',0) == -1)
	{
	alert("\nThe Email field requires a \"@\" and a \".\"be used.\n\nPlease re-enter your e-mail address.")
	document.forms["theForm"].email.select();
	document.forms["theForm"].email.focus();
	return false;
	}
}
			
function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
	thisfield.value = "";
	}
}

function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
	thisfield.value = defaulttext;
	}
}

//================================================
// function validateSubscribe(theform)
//================================================
function validateSubscribe(theform){
	var errors="";
	
//	if(Trim(theform.FirstName.value)==""){
//		errors+="First name is a required field.\n"
//	}
//	if(Trim(theform.LastName.value)==""){
//		errors+="Last name is a required field.\n"
//	}
//	if(Trim(theform.ChurchName.value)==""){
//		errors+="Church name is a required field.\n"
//	}
//	if(Trim(theform.Position.value)==""){
//		errors+="Church position is a required field.\n"
//	}
//	if(Trim(theform.Address1.value)==""){
//		errors+="Address is a required field.\n"
//	}
//	if(Trim(theform.City.value)==""){
//		errors+="City is a required field.\n"
//	}
//	if(Trim(theform.State.value)==""){
//		errors+="State is a required field.\n"
//	}
//	if(Trim(theform.ZipCode.value)==""){
//		errors+="Zip code is a required field.\n"
//	}
//	if(Trim(theform.Phone1.value)==""){
//		errors+="Phone is a required field.\n"
//	}
	if(!validateEmail(theform.emailAddress.value)){
		errors+="Please enter a valid email address.\n";
	}
	/*
	if(!theform.WCharts.checked && !theform.WVideo.checked && !theform.WDrama.checked && !theform.WMessages.checked){
		errors+="\nYou must specify one or more newsletters you would like to subscribe to.\n"
	}
	*/
	
	if(errors==""){
		return true;
	} else {
		alert(errors);
		return false;
	}
}
//================================================
// function validateUnsubscribe(theform)
//================================================
function validateUnsubscribe(theform){
	var errors="";
	if(!validateEmail(theform.EmailAddress.value)){
		errors+="Please enter a valid email address.\n";
	}
	/*
	if(!theform.WCharts.checked && !theform.WVideo.checked && !theform.WDrama.checked && !theform.WMessages.checked){
		errors+="\nYou must specify one or more newsletters you would like to unsubscribe from.\n"
	}
	*/
	
	if(errors==""){
		return true;
	} else {
		alert(errors);
		return false;
	}
}
//================================================
// function validateEmail(emailStr)
//================================================
function validateEmail(emailStr) {
	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);

	if (matchArray==null) {
		//Email address seems incorrect (check @ and .'s)
		return false;
	}

	var user=matchArray[1];
	var domain=matchArray[2];

	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			//The username contains invalid characters.
			return false;
		}
	}

	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			//The domain name contains invalid characters.
			return false;
		}
	}

	if (user.match(userPat)==null) {
		//The username doesn't seem to be valid.
		return false;
	}

	var IPArray=domain.match(ipDomainPat);
	
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				//Destination IP address is invalid!
				return false;
			}
		}
		return true;
	}
 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;

	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			//The domain name does not seem to be valid.
			return false;
		}
	}

	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) {
		//The address must end in a well-known domain or two letter country.
		return false;
	}

	if (len<2) {
		//This address is missing a hostname.
		return false;
	}
	return true;
}
//================================================
// function Trim(TRIM_VALUE)
//================================================
function Trim(TRIM_VALUE){
	if(TRIM_VALUE.length < 1){
		return "";
   	}
   	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);

   	if(TRIM_VALUE==""){
   		return "";
   	} else {
   		return TRIM_VALUE;
   	}
}
//================================================
// function RTrim(VALUE)
//================================================			
function RTrim(VALUE){
   	var w_space = String.fromCharCode(32);
   	var v_length = VALUE.length;
   	var strTemp = "";
   	if(v_length < 0){
   		return "";
   	}
   	var iTemp = v_length -1;
   	while(iTemp > -1){
   		if(VALUE.charAt(iTemp) == w_space){
		} else {
   			strTemp = VALUE.substring(0,iTemp +1);
   			break;
   		}
   		iTemp = iTemp-1;
   	}
   	return strTemp;
}
//================================================
// function LTrim(VALUE)
//================================================			
function LTrim(VALUE){
   	var w_space = String.fromCharCode(32);
   	if(v_length < 1){
   		return"";
   	}
   	var v_length = VALUE.length;
   	var strTemp = "";
   	var iTemp = 0;
   	while(iTemp < v_length){
   		if(VALUE.charAt(iTemp) == w_space){
		} else {
   			strTemp = VALUE.substring(iTemp,v_length);
   			break;
   		}
   		iTemp = iTemp + 1;
   	}
   	return strTemp;
}

function SubmitSearch(formObj)
{
	var strParameters = ""	
	
	strParameters = 'site=' + document.formsearch.site.value
	strParameters = strParameters + '&client='+ document.formsearch.client.value
	strParameters = strParameters + '&proxystylesheet='+ document.formsearch.proxystylesheet.value
	strParameters = strParameters + '&output='+ document.formsearch.output.value
	strParameters = strParameters + '&filter='+ document.formsearch.filter.value
	strParameters = strParameters + '&getfields='+ document.formsearch.getfields.value
	strParameters = strParameters + '&q='+ document.formsearch.q.value	
	
	var selectedValue
	selectedValue = document.formsearch.select.value
	//Products, Community, Training
	if (selectedValue == "grouplife")
	{
		strParameters = strParameters + '&requiredfields=' + 'googlecat:sets|googlecat:training|googlecat:seasonal|googlecat: training|googlecat: seasonal|googlecat:kits|googlecat:transcripts|googlecat:other|googlecat:broch|googlecat:books|googlecat:music|googlecat:video|googlecat:drama|googlecat:message|connectiongrp:blog' + '&partialfields=ministry:grp'
	}
	else if (selectedValue == "training")
	{
		strParameters = strParameters + '&requiredfields=' + 'googlecat:training|googlecat: training' + '&partialfields=ministry:grp'
	}	
	else if (selectedValue == "resources")
	{
		strParameters = strParameters + '&requiredfields=' + 'googlecat:books|googlecat:music|googlecat:video|googlecat:drama|googlecat:message|googlecat:training|googlecat: training|googlecat:seasonal|googlecat: seasonal|googlecat:kits|googlecat:sets|googlecat:broch|googlecat:other' + '&partialfields=ministry:grp'
	}
	else if (selectedValue == "community")
	{
		strParameters = strParameters + '&requiredfields=' + 'connectiongrp:blog' + '&partialfields=ministry:grp'
	}		
	else if (selectedValue == "entiresite")
	{
		strParameters = strParameters + '&requiredfields=' + 'googlecat:sets|googlecat:training|googlecat:seasonal|googlecat: training|googlecat: seasonal|googlecat:kits|googlecat:transcripts|googlecat:other|googlecat:broch|googlecat:books|googlecat:music|googlecat:video|googlecat:drama|googlecat:message|connectiongrp:blog'
	}		
	strParameters  = strParameters.replace("'"," ")
	strParameters  = strParameters.replace("'"," ")
	strParameters  = strParameters.replace('"','')
	
	//UserSearch('arts',formsearch)
	
	document.formsearch.action = "/grouplife/searchresult.asp?" + strParameters
	document.formsearch.submit();
	return true;
}