
function hasValue(elem)
{
	var str = elem.value;
	if (str.length == 0){
		return false;
	}
	return true;
}

function isChecked(elem)
{
	if (elem.checked)
		return true;
	else 
		return false;
}

function minLength(elem,minsize)
{
	var str = elem.value;
	if (str.length < minsize){
		return false;
	}
	return true;
}

function validEmail(elem)
{
	var x = elem.value
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(x)) 
		return true;
	else 
		return false;
}
function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

function validEmails(elem)
{
	var x = elem.value
	x = trim(x);
	var array=x.split("\n");

	for(var i=0;i<array.length;i++)
	{
	var y=array[i];
    y=trim(y);
	
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(y)) 
	{

	}
	else 
	{
		return false;
	}
	
	
	}
	return true;
		
		
}

function validateFindMessage(form)
{
   if(!hasValue(form.SearchText))
   {
   alert('Please enter in a location.');
   return false;
   
   }

   return true;
}

function validateAddMessage(form)
{
 if(!hasValue(form.SearchText))
   {
   alert('Please enter a location.');
   return false;
   
   }
   if(!hasValue(form.subject))
   {
   alert('Please enter a subject.');
   return false;
   
   }
   if(!hasValue(form.comment))
   {
   alert('Please enter a comment.');
   return false;
   
   }
   if(!hasValue(form.SearchText))
   {
   alert('Please enter a location.');
   return false;
   
   }
   if(!hasValue(form.subject))
   {
   alert('Please enter a subject.');
   return false;
   
   }
   if(!hasValue(form.comment))
   {
   alert('Please enter a comment.');
   return false;
   
   }
   return true;

}

function validateAddMessageQuick(form)
{
   if(!hasValue(form.subject))
   {
   alert('Please enter a subject.');
   return false;
   
   }
   if(!hasValue(form.comment))
   {
   alert('Please enter a comment.');
   return false;
   
   }
   return true;

}

function validateAddReply(form)
{
  
   if(!hasValue(form.comment))
   {
   alert('Please enter a comment.');
   return false;
   
   }
   return true;

}


function validateAddFavCity(form)
{
	if (!hasValue(form.label))
	{
		alert('Please specify a label for this location.');
		return false;
	}
	if (!hasValue(form.where))
	{
		alert('Please specify a location.');
		return false;
	
	}
	return true;
}

function validateFindDestination(form)
{
	if (!hasValue(form.SearchText))
	{
		alert('Please Enter a Neighborhood to Search');
		return false;
	}
	return true;
}

function radioSelected(radio)
{
	var isclicked = false;
	for (count = 0; count < radio.length; count++)
	{
		if (radio[count].checked)
			return true; 
	}
return false;
}


function validateFindPopCity(form)
{

	if (!radioSelected(form.city))
	{
		alert('Please Select A City');
		return false;
	}
	
	return true;
}

function validateAddDestination(form)
{
	if (!hasValue(form.Name))
	{
		alert('Name must be filled in.');
		return false;
	}
	if (!hasValue(form.City))
	{
		alert('Please enter the city.');
		return false;
	}
	if (!hasValue(form.State))
	{
		alert('Please enter the state.');
		return false;
	}
	if (!hasValue(form.Comments))
	{
		alert('Comments must be filled in.');
		return false;
	}
	if (!hasValue(form.Rating))
	{
		alert('Please rate this suggestion.');
		return false;
	}
	
	
	return true;
}

function validatePreAddDestination(form)
{
	if (!hasValue(form.Name))
	{
		alert('Please enter the name of what you are trying to add.');
		return false;
	}
	if (!hasValue(form.where))
	{
		alert('Please enter where the place is.');
		return false;
	}
	
	return true;
}

function validateAddEntryMini(form)
{
	if (!hasValue(form.Comments))
	{
		alert('Comments must be filled in.');
		return false;
	}
	if (!hasValue(form.Rating))
	{
		alert('Please select a rating by clicking on the stars.');
		return false;
	}
	return true;
}
	
function validateCompleteAddDestination(form)
{
	if (!hasValue(form.Name))
	{
		alert('Name must be filled in.');
		return false;
	}
	if (!hasValue(form.Address))
	{
		alert('Address must be filled in.');
		return false;
	}
	if (!hasValue(form.City))
	{
		alert('Please enter the city.');
		return false;
	}
	if (!hasValue(form.State))
	{
		alert('Please enter the state.');
		return false;
	}

	if (!hasValue(form.Category))
	{
		alert('Please Select a Category.');
		document.getElementById('selCatLabel').style.background = 'red';
		return false;
	}
	/*if (!hasValue(form.Rating))
	{
		alert('Please select a rating by clicking on the stars.');
		return false;
	}*/
		
	
	return true;
}

function validateNewPass(form)
{
	if (!hasValue(form.oldPass))
	{
		alert('Please enter your current password.');
		return false;
	}
	if (!hasValue(form.newPass1) || !(hasValue(form.newPass2)))
	{
		alert('Please complete both your new password and new password confirmation fields.');
		return false;
	}
	if (!minLength(form.newPass1,4))
	{
		alert('Your password must be at least 4 characters long');
		return false;
	}
	if (form.newPass1.value!=form.newPass2.value)
	{
		alert('Your new passwords are not the same, unable to confirm new password.');
		return false;
	}
	return true;
}

function validateRegisterUser(form)
{
	if (!hasValue(form.email))
	{
		alert('Email must be filled in.');
		return false;
	}
	if (!validEmail(form.email))
	{
		alert('Please enter a valid email address.');
		return false;
	}
	if (!minLength(form.password,4))
	{
		alert('Your password must be at least 4 characters long');
		return false;
	}
	if (form.password.value != form.password2.value)
	{
		alert('Your password do not match.  Please correct and resubmit');
		return false;
	}
	/*
	if (!hasValue(form.fname))
	{
		alert('Please enter your first name.');
		return false
	}
	if (!hasValue(form.lname))
	{
		alert('Please enter your last name.  Note: your last name will not be shared with others, only your initial will be used to identify you.');
		return false
	}
	
	if (!hasValue(form.city) || !hasValue(form.State))
	{
		alert('Please enter your city and state.');
		return false;
	}
	*/
	//if (!hasValue(form.guess))
	//{
	//	alert('Please enter image verification text');
	//	return false;
	//}
	if (!hasValue(form.zip))
	{
		alert('Your Zip Code is required.');
		return false
	}
	if (!hasValue(form.nickname))
	{
		alert('A valid nickname is required.');
		return false
	}
	if (!minLength(form.nickname,3))
	{
		alert('Your nickname must be at least 3 characters.');
		return false;
	}
	if (!isChecked(form.terms))
	{
		alert('Please indicate that you have read and agree with the terms of use agreement.');
		return false;
	}
	return true;
}

function validateUpdateUser(form)
{
	if (!hasValue(form.email))
	{
		alert('Email must be filled in.');
		return false;
	}
	if (!validEmail(form.email))
	{
		alert('Please enter a valid email address.');
		return false;
	}
	if (!hasValue(form.nickname))
	{
		alert('Please enter a nickname to be displayed to other users.');
		return false
	}
	if (!minLength(form.nickname,3))
	{
		alert('Your nickname must be at least 3 characters.');
		return false;
	}
	if (!hasValue(form.zip))
	{
		alert('Please enter your zip code.');
		return false;
	}
	return true;
}


function validateAddFriend(form)
{
	if (!hasValue(form.email))
	{
		alert('Email must be filled in.');
		return false;
	}
	if (!validEmail(form.email))
	{
		alert('Please enter a valid email address.');
		return false;
	}
	return true;

}

function validInvite(form)
{
	if (!hasValue(form.inviteemail))
	{
		alert('Invite Email must be filled in.');
		return false;
	}
	if (!validEmail(form.inviteemail))
	{
		alert('Please enter a valid email address.');
		return false;
	}
	form.email.value = "";
	return true;

}

function validInvites(form)
{
	if (!hasValue(form.inviteemail))
	{
		alert('Invite Email must be filled in.');
		return false;
	}
	
	if (!validEmails(form.inviteemail))
	{
		alert('Please enter a valid email addresses.');
		return false;
	}
	//form.email.value = "";
	return true;

}

function validateForgotPass(form)
{
	if (!hasValue(form.email) || !validEmail(form.email))
	{
		alert('Please enter your email address before clicking forgot password.');
		return false;
	}
	return true;
}

function submitForgotPass(form)
{
	document.ForgotPass.email.value = form.email.value;
	document.ForgotPass.submit();
}
