// JavaScript Document

	//function validate(form)
//	{
//		alert ("FCK Editor value is "  + form.description.value);
//	}


	function limitText(limitField, limitNum)
	{
		if (limitField.value.length > limitNum)
		{
			limitField.value = limitField.value.substring(0, limitNum);
		}
		else 
		{
			document.getElementById("charsLeft").innerHTML= (limitNum - limitField.value.length);
		}
	}


	function isBlank(data)
	{
		// Remove all cases of "<br>" and "&nbsp;"
		data = data.replace(/\r|\n|\<br>|\&nbsp;/g, "");
		// Remove all spaces
		data = data.replace(/\s/g, "");	

		if (data == '')
			return true;
		else
			return false;	
	}

	function confirmYesNo()
	{
		return confirm("Are you sure?");
	}



	function validateExchangeLinkForm(form)
	{			
		var errorString='';

		if (isBlank(form.name.value))
		{		
			errorString = errorString + "- Name\n";
		}

		if (isBlank(form.phone.value))
		{
			errorString = errorString + "- Phone\n";
		}

		if (isBlank(form.email.value))
		{
			errorString = errorString + "- Email\n";
		}

		if (isBlank(form.title.value))
		{
			errorString = errorString + "- Link Title\n";
		}

		if ((isBlank(form.hyperlink.value)) || (form.hyperlink.value == "http://"))
		{
			errorString = errorString + "- Your Link\n";
		}

		if ((isBlank(form.location.value)) || (form.location.value == "http://"))
		{
			errorString = errorString + "- Link Location\n";
		}
		
		if (isBlank(form.linkDescription.value))
		{
			errorString = errorString + "- Description\n";
		}

		if (errorString!='')
		{
			alert("The following information is required:\n" + errorString);
			return false;
		}
		else
		{
			return true;
		}
	}

	function validateCreateWebsiteForm(form)
	{	
		var theMLSColumns = form.mlsColumns.value;
		theMLSColumns = theMLSColumns.replace(/\D/g, "");		
		if ((isBlank(theMLSColumns)) || (form.mlsColumns.value <= 0))
		{
			alert("You must enter a number greater than zero for columns!");
			return false;
		}				

		var theDomain = form.domain.value;
		var httpString = theDomain.match("http://www.");
		if ((isBlank(theDomain)) || (httpString == null))
		{
			alert("You must enter a domain and it must be in the format http://www.<domain name>\nExamples: http://www.yourdomain.com, http://www.yourdomain.net, http://www.yourdomain.org");
			return false;
		}				

		var theMLSRadius = form.mlsRadius.value;
		theMLSRadius = theMLSRadius.replace(/\D/g, "");		
		if ((isBlank(theMLSRadius)) || (form.mlsRadius.value <= 0))
		{
			alert("You must enter a number greater than zero for the MLS Radius!");
			return false;
		}				

		var theMLSNumberOfCities = form.mlsNumberOfCities.value;
		theMLSNumberOfCities = theMLSNumberOfCities.replace(/\D/g, "");		
		if ((isBlank(theMLSNumberOfCities)) || (form.mlsNumberOfCities.value <= 0))
		{
			alert("You must enter a number greater than zero for the MLS # of Cities!");
			return false;
		}				


		return true;
	}




	function validateContactForm(form)
	{
		if (form.name.value == '')
		{
			alert("You must enter a name!");
			return false;
		}

		if (form.email.value == '')
		{
			alert("You must enter an email address!");
			return false;
		}

		if (form.phone.value == '')
		{
			alert("You must enter a phone address!");
			return false;
		}

		if (form.content.value == '')
		{
			alert("You must enter comments!");
			return false;
		}

		return true;
	}

	function validateArticleForm()
	{			
		if (title.value == '')
		{
			alert("You must enter a title");
			return false;
		}

		if (author.value == '')
		{
			alert("You must enter an author!");
			return false;
		}

		if (source.value == '')
		{
			alert("You must enter a source");
			return false;
		}
		
		if (hyperlink.value == '')
		{
			alert("You must enter a link!");
			return false;
		}

		if (checkFCKEditorContent("fckEditorContent") == false)
		{
			alert("You must enter the article content!");
			return false;
		}

		return true;
	}


	function validateGuideLinkForm()
	{			
		if (categoryID.value == '')
		{
			alert("You must enter a category!");
			return false;
		}

		if (title.value == '')
		{
			alert("You must enter a title!");
			return false;
		}


		if (hyperlink.value == '')
		{
			alert("You must enter a link!");
			return false;
		}


		if (checkFCKEditorContent("description") == false)
		{
			alert("You must enter the guide link description!");
			return false;
		}

		return true;
	}

	function validateBDLF(form)
	{			
		if (isBlank(form.name.value))
		{
			alert("You must enter a name!");
			return false;
		}

		if (isBlank(form.phone.value))
		{
			alert("You must enter a phone number!");
			return false;
		}

		if (isBlank(form.email.value))
		{
			alert("You must enter an email!");
			return false;
		}

		if (isBlank(form.title.value))
		{
			alert("You must enter a title!");
			return false;
		}

		if (isBlank(form.hyperlink.value))
		{
			alert("You must enter a link!");
			return false;
		}
		
		if (isBlank(form.categoryID.value))
		{
			alert("You must enter a category!");
			return false;
		}

		if (isBlank(form.description.value))
		{
			alert("You must enter a description!");
			return false;
		}

		return true;
	}

	function validateTestimonialForm(form)
	{			
		
		if (form.name.value == '')
		{
			alert("You must enter a name!");
			return false;
		}

		if (form.location.value == '')
		{
			alert("You must enter a location!");
			return false;
		}

		if (checkFCKEditorContent("testimonial") == false)
		{
			alert("You must enter the guide link description!");
			return false;
		}

		return true;
	}

	function validateGuideCategoryForm(form)
	{					
		if (form.name.value == '')
		{
			alert("You must enter a name!");
			return false;
		}

		return true;
	}


	function validateTeamInfoForm(form)
	{					 
		if (form.name.value == '')
		{
			alert("You must enter a name!");
			return false;
		}

		if (form.slogan.value == '')
		{
			alert("You must enter a slogan!");
			return false;
		}

		if (checkFCKEditorContent("description") == false)
		{
			alert("You must enter a description!");
			return false;
		}

		return true;
	}



	function validateTeamMemberForm(form)
	{					 
		if (form.name.value == '')
		{
			alert("You must enter a name!");
			return false;
		}

		if (checkFCKEditorContent("description") == false)
		{
			alert("You must enter a description!");
			return false;
		}

		return true;
	}

	function validateRelocationGuide(form)
	{	
		if (isBlank(form.first_name.value))
		{
			alert("You must enter your first name!");
			return false;
		}		
		
		if (isBlank(form.last_name.value))
		{
			alert("You must enter your last name!");
			return false;
		}		

		if (isBlank(form.email.value))
		{
			alert("You must enter your email address!");
			return false;
		}		
		if (isBlank(form.address_1.value))
		{
			alert("You must enter your address!");
			return false;
		}		
		if (isBlank(form.city.value))
		{
			alert("You must enter your City!");
			return false;
		}		
		if (isBlank(form.state.value))
		{
			alert("You must enter your State!");
			return false;
		}		
		if (isBlank(form.zip.value))
		{
			alert("You must enter your zip code!");
			return false;
		}		
		if (isBlank(form.phone.value))
		{
			alert("You must enter your Main Telephone number!");
			return false;
		}		

		return true;
	}



	function checkFCKEditorContent(fckEditorInstanceName)
	{
		var oEditor = FCKeditorAPI.GetInstance(fckEditorInstanceName);		
		var content = oEditor.GetHTML(true);

		// Remove all cases of "<br>" and "&nbsp;"
		content	= content.replace(/\r|\n|\<br>|\&nbsp;/g, "");
		// Remove all spaces
		content = content.replace(/\s/g, "");	

		// Check if content is empty
		if (content == '')
		{
			return false;
		}
		else
		{
			return true;
		}
	}

	function removeCharacters( strValue, strMatchPattern ) 
	{
	/************************************************
	DESCRIPTION: Removes characters from a source string
	  based upon matches of the supplied pattern.

	PARAMETERS:
	  strValue - source string containing number.

	RETURNS: String modified with characters
	  matching search pattern removed

	USAGE:  strNoSpaces = removeCharacters( ' sfdf  dfd',
									'\s*')
	*************************************************/
	 var objRegExp =  new RegExp( strMatchPattern, 'gi' );

	 //replace passed pattern matches with blanks
	  return strValue.replace(objRegExp,'');
	}
