/*
#############################################################################
# eLuminous Technologies - Copyright (C)  http://eluminoustechnologies.com 
# This code is written by eLuminous Technologies, Its a sole property of 
eLuminous Technologies and cant be used / modified without license.  
Any changes/ alterations, illegal uses, unlawful distribution, copying is strictly
prohibhited #
#############################################################################

# Name: validations.js
# Usage: included ( WRITE USAGE DETAILS ) 
  {
   -- It is called from index.php & header.php in admin panel
  } 
# Update: created on 11-Dec-2006 by swati patel
# Status: production
# Purpose: Contains javascript validations functions for various files in admin panel.
 
#############################################################################
ALSO STRICTLY MAINTAINING THE LOGS OF CHANGES AND PERSON NAME 
#############################################################################

##################################### List of functions ##################################

1.  function validateForgotPassword(frm)
2. 	function validateLogin(frm)
3.  function validateAdmChangePass(frm)
4.  function IsNumeric(expression)
5.  function validateAddBuilder(frm)
6.  function validateBuilderProfile(frm)
##################################### end of functions list ###############################
*/

//validates forgot password form
function validateForgotPassword(frm)
{	
	if(frm.txt_email.value == "")
	{
		alert("Please fill in email.");
		frm.txt_email.focus();
		return false;
	}
	return true;	
}

//validates admin login form
function validateLogin(frm)
{	
	if(frm.txt_email.value == "")
	{
		alert("Please fill in email.");
		frm.txt_email.focus();
		return false;
	}
	if(frm.txt_password.value == "")
	{
		alert("Please fill in password.");
		frm.txt_password.focus();
		return false ;
	}
	return true;	
}

//validates admin change password form
function validateChangePass()
{ 	
	var frm = document.frmchgpwd;
	
	if (trim(frm.old_password.value) == "")			{ alert("Please fill in old password"); frm.old_password.focus(); return false; }
	else if (trim(frm.new_password.value) == "")	{ alert("Please fill in new password"); frm.new_password.focus(); return false; }
	else if (trim(frm.confirm_pass.value) == "")	{ alert("Please fill in confirm password"); frm.confirm_pass.focus(); return false; }
	else if (frm.new_password.value.length < 6)  
	{ 
		alert ( "New password must be at least 6 characters long"); 
		frm.new_password.focus(); 
		return false; 
	}
	else if (trim(frm.confirm_pass.value) != trim(frm.new_password.value))  
		{ 
			alert ( "New password and confirm password must be same"); 
			frm.new_password.focus(); 
			return false; 
		}
	else
		return true;	
}

//Function to check pure numbers
function IsNumeric(expression) 
{
	var nums = "0123456789";
	if (expression.length==0)return(false);
	for (var n=0; n < expression.length; n++)
	{
		if(nums.indexOf(expression.charAt(n))==-1)return(false);
	}
	return(true);
}

	function isFilled(str){ return (str != ""); }

	function isEmail(string) { return (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1); }

 	//function isDigital(str)	{ return(parseInt(str,10)==(str*1)); /*return(parseFloat(str,10)==(str*1));*/ }

 	function isPhone(val) { 	var re = /^(\$?\d+\$?|\$?\d+\.\d+\$?)$/; return (re.test(val)); }
	//function isCurrency(val) { 	var re = /^(\$?\d+\$?|\$?\d+\.\d+\$?)$/; return (re.test(val)); }
	
function validate(req,email,digits,currs)
{
	var field, i;
	var req_len = parseInt(req.length);
	var email_len = parseInt(email.length);
	var digits_len = parseInt(digits.length);
	var currs_len = parseInt(currs.length);
	
	for (i=0;i<req_len;i++)
	{
			var field = document.getElementById(req[i]);
			if (field)
			{
				field.style.border="1px solid #000000";
				if ((field.type == 'checkbox')||(field.type == 'radio'))
				{
					var field = document.getElementsByName(req[i]);
					var chk = false;
					for(l=0;l<field.length;l++)
					{
						if (field[l].checked) chk = true;
					}
					if (!chk) 
					{
						//alert("Field '" + field[0].title + "' is required to be checked correctly before successful submission.");
						//alert ("Please select " + field[0].title+"." );
						alert (field[0].title);
						field[0].style.border="1px solid #FF0000";
						return false; 
						break;
					}
				}
				else
				{
					if (!isFilled(trim(field.value)))
						{
						//alert("Field '" + field.title + "' is required to be filled in before successful submission.");
						//alert ("Please fill " + field.title+"." );
						alert (field.title);
						field.value="";
						field.focus();
						field.style.border="1px solid #FF0000";
						return false;
						// break;
						}
				}
			}
			else
				alert(req[i] + " does not exist" );		
	}


		for (i=0;i<email_len;i++)
		{
			var field = document.getElementById(email[i]);
			field.style.border="1px solid #000000";
			if (!isEmail(trim(field.value)))
			 {
				//alert("Field '" + field.title + "' is required to be filled in with valid email addresses before successful submission.");
				alert("Please fill in valid email address.");
				field.style.border="1px solid #FF0000";
				field.focus();
				return false;
				break;
			}
		}

		for (i=0;i<digits_len;i++)
		{

			var field = document.getElementById(digits[i]);
				field.style.border="1px solid #000000";
			if ( field.value !="")
			{
					if(isNaN(field.value)==true)
						{ 
							alert("Please fill in valid numeric value.");
							field.style.border="1px solid #FF0000";
							field.focus();
							return false;
							break;
						} 
				
				/*if (!isDigital(trim(field.value))) 
				{
					//alert("Field " + field.title + " is required to be filled in only with digits (0-9) and decimal point before successful submission.");
					//alert("Please fill only digits(0-9) and decimal point in "+field.title + ".");
					alert("Please fill in valid numeric value.");
					field.style.border="1px solid #FF0000";
					field.focus();
					return false;
					break;
				}	*/
			}
		}

		for (i=0;i<currs_len;i++)	{

			var field = document.getElementById(currs[i]);
				field.style.border="1px solid #000000";
			if (!isCurrency(trim(field.value))) {

				//alert("Field " + field.title + " is required to be filled in only with digits (0-9) a decimal point, or a dollar sign before successful submission.");
				alert("Please fill only digits(0-9) and decimal point in "+field.title + ".");
				field.style.border="1px solid #FF0000";
				field.focus();
				return false;
				break;

			}}

		return true;
}


//validates registration form
function validate_registration(frm)
{
	// check for blanks
	var req_fields = Array("txt_username", "txt_email", "txt_pass", "txt_confpass", "txt_fname", "txt_lname", "txt_address1", "txt_address2", "txt_city", "txt_state", "sel_country", "txt_phone", "txt_zipcode", "turing_number");
	var blank_fields = "";
	var k=1;
	
	//loop throgh all the elements and remove the red color border
	for(var n=0; n<frm.length; n++)
	{
		if(frm.elements[n].type == "text" || frm.elements[n].type == "checkbox" || frm.elements[n].type == "select" || frm.elements[n].type=="radio" || frm.elements[n].type == "textarea" || frm.elements[n].type == "file")
		{
			var cnt_id = frm.elements[n].id;
			document.getElementById(cnt_id).style.border ="1px solid #000000";
		}
	}
	for (var i=0; i<req_fields.length; i++)
	{
		if(LTrim(document.getElementById(req_fields[i]).value) == "")
		{
			//alert( document.getElementById(req_fields[i]).title);
			blank_fields += "\n" + k + ".  " + document.getElementById(req_fields[i]).title;
			show_err_border(req_fields[i]);
			k++;
		}//if
	}//for
	if(blank_fields != "")
	{
		alert("Please fill in following field(s)." + blank_fields);
		return false;
	}
	else
	{
		//check for other validations
		
		//check for valid email
		if(!emailcheck(frm.txt_email.value))
		{
			alert("Please enter a valid email address.");
			frm.txt_email.focus();
			show_err_border("txt_email");
			return false;
		}
		//validate password length
		if(frm.txt_pass.value.length < 6)
		{
			alert("Please enter a valid email address.");
			frm.txt_pass.focus();
			show_err_border("txt_pass");
			return false;
		}
		//validate for equality of password and confirm password
		if(frm.txt_pass.value != frm.txt_confpass.value)
		{
			alert("Password and confirm password must be equal.");
			frm.txt_pass.focus();
			show_err_border("txt_pass");
			show_err_border("txt_confpass");
			return false;
		}
		//validate phone no
		if(!isNum(frm.txt_phone.value))
		{
			alert("Invalid phone no!! Please enter only numbers in phone no field.");
			frm.txt_phone.focus();
			show_err_border("txt_phone");
			return false;
		}
		//validate zipcode
		if(!isNum(frm.txt_zipcode.value))
		{
			alert("Invalid zipcode!! Please enter only numbers in zipcode field.");
			frm.txt_zipcode.focus();
			show_err_border("txt_zipcode");
			return false;
		}
		//validate turing no
		if(frm.turing_number.value != frm.turing_find.value)
		{
			alert("Invalid verification code!! Please enter correct verification code.");
			frm.turing_number.focus();
			show_err_border("turing_number");
			return false;
		}
		
	}
	return true;
}

//validates edit profile form
function validate_edit_profile(frm)
{
	// check for blanks 
	var req_fields = Array("txt_email", "txt_fname", "txt_lname", "txt_address1", "txt_address2", "txt_city", "txt_state", "sel_country", "txt_phone", "txt_zipcode", "turing_number");
	var blank_fields = "";
	var k=1;
	
	//loop throgh all the elements and remove the red color border
	for(var n=0; n<frm.length; n++)
	{
		if(frm.elements[n].type == "text" || frm.elements[n].type == "checkbox" || frm.elements[n].type == "select" || frm.elements[n].type=="radio" || frm.elements[n].type == "textarea" || frm.elements[n].type == "file")
		{
			var cnt_id = frm.elements[n].id;
			document.getElementById(cnt_id).style.border ="1px solid #000000";
		}
	}
	for (var i=0; i<req_fields.length; i++)
	{
		if(LTrim(document.getElementById(req_fields[i]).value) == "")
		{
			//alert( document.getElementById(req_fields[i]).title);
			blank_fields += "\n" + k + ".  " + document.getElementById(req_fields[i]).title;
			show_err_border(req_fields[i]);
			k++;
		}//if
	}//for
	if(blank_fields != "")
	{
		alert("Please fill in following field(s)." + blank_fields);
		return false;
	}
	else
	{
		//check for other validations
		
		//check for valid email
		if(!emailcheck(frm.txt_email.value))
		{
			alert("Please enter a valid email address.");
			frm.txt_email.focus();
			show_err_border("txt_email");
			return false;
		}
		
		//validate phone no
		if(!isNum(frm.txt_phone.value))
		{
			alert("Invalid phone no!! Please enter only numbers in phone no field.");
			frm.txt_phone.focus();
			show_err_border("txt_phone");
			return false;
		}
		//validate zipcode
		if(!isNum(frm.txt_zipcode.value))
		{
			alert("Invalid zipcode!! Please enter only numbers in zipcode field.");
			frm.txt_zipcode.focus();
			show_err_border("txt_zipcode");
			return false;
		}
		//validate turing no
		if(frm.turing_number.value != frm.turing_find.value)
		{
			alert("Invalid verification code!! Please enter correct verification code.");
			frm.turing_number.focus();
			show_err_border("turing_number");
			return false;
		}
	}
	return true;
}



//Function to validate Builder while registeration
function validateAddBuilder(frm)
{
	var req 		= new Array("txt_contact_name","txt_phone_no","txt_email","txt_company_name","txt_company_addr1","txt_how_u_hear");
	var email 		= new Array();
	var digits 		= new Array();
	var currs 		= new Array();
	var res = validate(req,email,digits,currs);
	if (res == false)
	{
		return res;
	}
	else
	{
		if(frm.chk_advance_desired_state)
		{
			if(!is_checkboxes_checked(frm.chk_advance_desired_state))
			{
				alert("Please select company states.");
				return false;
			}
			else
			{
				// -- COUNTY VALIDATIONS
				//if(frm.chk_advance_desired_county)
				{
					/*
					// -- COUNTY VALIDATIONS
					if(!is_checkboxes_checked(frm.chk_advance_desired_county))
					{
						alert("Please select county/counties.");
						return false;
					}
					else*/
					{
						var req 		= new Array("txt_city","txt_company_zip","txt_company_website","txt_password","txt_confirm_password");
						var email 		= new Array("txt_email");
						var digits 		= new Array();
						var currs 		= new Array();
						var res = validate(req,email,digits,currs);
						if (res == false)
						{
							return res;
						}
						else
						{
							if(!IsNumeric(frm.txt_phone_no.value) || frm.txt_phone_no.value < 0)
							{
								alert("Invalid phone no!! Please enter only numbers in phone no field.");
								frm.txt_phone_no.focus();
								show_err_border("txt_phone_no");
								return false;
							}
							else if(!IsNumeric(frm.txt_company_zip.value) || frm.txt_company_zip.value < 0)
							{
								alert("Invalid company zip code!! Please enter only numbers in zip code field.");
								frm.txt_company_zip.focus();
								show_err_border("txt_company_zip");
								return false;
							}
							else if(!checkUrl(frm.txt_company_website))
							{
								alert("Invalid company website!! Please refer following format: http://www.yoursitename.com or http://www.yoursitename.com/subdomainname.");
								frm.txt_company_website.focus();
								show_err_border("txt_company_website");
								return false;
							}
							else if(frm.txt_password.value.length < 6)
							{
								alert("Password must be of atleast 6 characters long.");
								frm.txt_password.focus();
								show_err_border("txt_password");
								return false;
							}
							else if(frm.txt_password.value != frm.txt_confirm_password.value)
							{
								alert("Password and confirm password must be same.");
								frm.txt_confirm_password.focus();
								show_err_border("txt_confirm_password");
								return false;
							}
							else if(frm.chk_agree_terms.checked != true)
							{
								alert("Please read and agree to the Terms and Conditions.");
								return false;
							}
							else if(frm.chk_read_privacy_policy.checked != true)
							{
								alert("Please read and agree to the Privacy Policy.");
								return false;
							}
							else
							{
								return true;
							}
						}
					}
				}
				// -- COUNTY VALIDATIONS
				/*else
				{
					alert("Please select county/counties.");
					return false;
				}*/
			}
		}
		else
		{
			alert("Please select company states.");
			return false;
		}	
	}
	return false;
}

// Function to validate basic search form
function validate_basci_search_info()
{
	var req 		= new Array("txt_basic_client_phone_no");
	var email 		= new Array();
	var digits 		= new Array("txt_basic_client_phone_no");
	var currs 		= new Array();
	return validate(req,email,digits,currs);
}

// Function to validate basic search form
function validateCheckClientStatusSearchInfo()
{
	var req 		= new Array("txt_css_client_phone_no");
	var email 		= new Array();
	var digits 		= new Array("txt_css_client_phone_no");
	var currs 		= new Array();
	return validate(req,email,digits,currs);
}

//Function to validate builder details for update
function validateBuilderProfile(frm)
{
	var req 		= new Array("txt_builder_email_addr", "txt_company_name","txt_company_addr1");
	var email 		= new Array();
	var digits 		= new Array();
	var currs 		= new Array();
	var res = validate(req,email,digits,currs);
	if (res == false)
	{
		return res;
	}
	else
	{
		if(frm.chk_advance_desired_state)
		{
			if(!is_checkboxes_checked(frm.chk_advance_desired_state))
			{
				alert("Please select company states.");
				return false;
			}
			else
			{
				//if(frm.chk_advance_desired_county)
				{
					/*
					if(!is_checkboxes_checked(frm.chk_advance_desired_county))
					{
						alert("Please select county/counties.");
						return false;
					}
					else
					*/
					{
						var req 		= new Array("txt_city","txt_company_zip","txt_company_website","txt_contact_name","txt_phone_no");
						var email 		= new Array("txt_builder_email_addr");
						var digits 		= new Array();
						var currs 		= new Array();
						var res = validate(req,email,digits,currs);
						if (res == false)
						{
							return res;
						}
						else
						{
							if(!checkUrl(frm.txt_company_website))
							{
								alert("Invalid company website!! Please refer following format: http://www.yoursitename.com or http://www.yoursitename.com/subdomainname.");
								frm.txt_company_website.focus();
								show_err_border("txt_company_website");
								return false;
							}
							else
							if(!IsNumeric(frm.txt_company_zip.value) || frm.txt_company_zip.value < 0)
							{
								alert("Invalid company zip code!! Please enter only numbers in zip code field.");
								frm.txt_company_zip.focus();
								show_err_border("txt_company_zip");
								return false;
							}
							else if(!IsNumeric(frm.txt_phone_no.value) || frm.txt_phone_no.value < 0)
							{
								alert("Invalid phone no!! Please enter only numbers in phone no field.");
								frm.txt_phone_no.focus();
								show_err_border("txt_phone_no");
								return false;
							}
							else
							{
								return true;	
							}
						}
					}
				}	
				/*else
				{
					alert("Please select county/counties.");
					return false;
				}*/
			}
		}
		else
		{
			alert("Please select company states.");
			return false;
		}	
	}
	return false;
}


// -- validate client registration form.
function validateAdvancedSearchClientInfo()
{
	if(document.getElementById('sel_desired_state').options[document.getElementById('sel_desired_state').selectedIndex].value == "")
	{
		alert("Please select desired area.");
		document.getElementById('sel_desired_state').style.border="1px solid #FF0000";
		document.getElementById('sel_desired_state').focus();
		return false;
	}
	else
	{
		if(document.frmSearchAdvanced.chk_advance_desired_county)
		{
			if(!is_checkboxes_checked(document.frmSearchAdvanced.chk_advance_desired_county))
			{
				alert("Please select county/counties.");
				return false;
			}
			else
			{
				if(document.frmSearchAdvanced.chk_advance_desired_citites)
				{
					if(!is_checkboxes_checked(document.frmSearchAdvanced.chk_advance_desired_citites))
					{
						alert("Please select City/Cities.");
						return false;
					}
					else
					{
						return true;
					}
				}
				else
				{
						alert("Please select City/Cities.");
						return false;
				}
			}
		}
		else
		{
				alert("Please select county/counties.");
				return false;
		}
	}
}

// -- validate client registration form.
function validateAdvancedSearchClientInfo_backup()
 {
	 //alert("in");
  /*var req   = new Array();
  var email   = new Array();
  var digits   = new Array();
  var currs   = new Array();
  
	var obj_Email = document.getElementById("txt_email");
	if(trim(obj_Email.value) != "")
	{
		emailLen = email.length;
		email[emailLen] = 'txt_email';
	}
	
	var obj_Phone = document.getElementById("txt_phone");
	if(trim(obj_Phone.value) != "")
	{
		digitsLen = digits.length;
		digits[digitsLen] = 'txt_phone';
	}
	*/
  if(true)//validate(req,email,digits,currs)
  {
	  //alert(document.getElementById('sel_desired_state').options[document.getElementById('sel_desired_state').selectedIndex].value);	
	  	/*if(trim(document.frmSearchAdvanced.txt_first_name.value) != "" )
		{ return true; }
		else
		if(trim(document.frmSearchAdvanced.txt_last_name.value) != "" )
		{ return true; }
		else
		if(trim(document.frmSearchAdvanced.txt_phone.value) != "" )
		{ 
			if(!IsNumeric(trim(document.frmSearchAdvanced.txt_phone.value)))
			{
				alert("Please fill in valid numeric value for phone number.");
				document.frmSearchAdvanced.txt_phone.style.border="1px solid #FF0000";
				document.frmSearchAdvanced.txt_phone.focus();
				return false;
			}
			return true; 
		}
		else
		if(trim(document.frmSearchAdvanced.txt_email.value) != "" )
		{
			if(!isEmail(trim(document.frmSearchAdvanced.txt_email.value)))
			{
				alert("Please valid email address.");
				document.frmSearchAdvanced.txt_email.style.border="1px solid #FF0000";
				document.frmSearchAdvanced.txt_email.focus();
				return false;
			}
			return true; 
		}
		else
		if(trim(document.frmSearchAdvanced.txt_adddr1.value) != "" )
		{ return true; }
		else
		if(trim(document.frmSearchAdvanced.txt_adddr2.value) != "" )
		{ return true; }
		else
		if(trim(document.frmSearchAdvanced.txt_state.value) != "" )
		{ return true; }
		else
		if(trim(document.frmSearchAdvanced.txt_city.value) != "" )
		{ return true; }
		else
		if(trim(document.frmSearchAdvanced.txt_zip.value) != "" )
		{ return true; }
		else*/
		
	  	if(document.getElementById('sel_desired_state').options[document.getElementById('sel_desired_state').selectedIndex].value != "")
		{ 
			/*if(document.frmSearchAdvanced.chk_advance_desired_county)
			{
				if(is_checkboxes_checked(document.frmSearchAdvanced.chk_advance_desired_county))
				{ return true; }
			}
			else //-- is any city selected
			if(document.frmSearchAdvanced.chk_advance_desired_county)
			{
				if(is_checkboxes_checked(document.frmSearchAdvanced.chk_advance_desired_citites))
				{ return true; }
			}*/
			return true;
		}
		else//-- is any county selected
		if(is_checkboxes_checked(document.frmSearchAdvanced.chk_advance_dwelling_type))
		{ return true; }
		else //-- is any levels selected
		if(is_checkboxes_checked(document.frmSearchAdvanced.chk_advance_levels))
		{ return true; }
		else
		if(trim(document.frmSearchAdvanced.txt_price_min.value) && trim(document.frmSearchAdvanced.txt_price_max.value))
		{
			if( parseInt(document.frmSearchAdvanced.txt_price_min.value) < parseInt(document.frmSearchAdvanced.txt_price_max.value) )
			{ return true; }
			else
			{
				alert ("Select minimum price less than maximum price.");
				document.frmSearchAdvanced.txt_price_min.style.border="1px solid #FF0000";
				document.frmSearchAdvanced.txt_price_max.style.border="1px solid #FF0000";
				document.frmSearchAdvanced.txt_price_min.focus();
				return false; 
			}
		}
		else
		if(trim(document.frmSearchAdvanced.txt_price_min.value) != "")
		{ return true; }
		else
		if(trim(document.frmSearchAdvanced.txt_price_max.value) != "")
		{ return true; }
		else
		if(trim(document.frmSearchAdvanced.txt_squr_feet_min.value) && trim(document.frmSearchAdvanced.txt_squr_feet_max.value))
		{
			if( parseInt(document.frmSearchAdvanced.txt_squr_feet_min.value) < parseInt(document.frmSearchAdvanced.txt_squr_feet_max.value) )
			{ return true; }
			else
			{
				alert ("Select minimum square feet less than maximum square feet.");
				document.frmSearchAdvanced.txt_squr_feet_min.style.border="1px solid #FF0000";
				document.frmSearchAdvanced.txt_squr_feet_max.style.border="1px solid #FF0000";
				document.frmSearchAdvanced.txt_squr_feet_min.focus();
				return false; 
			}
		}
		else
		if(trim(document.frmSearchAdvanced.txt_squr_feet_min.value) != "")
		{ return true; }
		else
		if(trim(document.frmSearchAdvanced.txt_squr_feet_max.value) != "")
		{ return true; }
		else
		if(trim(document.frmSearchAdvanced.txt_bedrooms_min.value) && trim(document.frmSearchAdvanced.txt_bedrooms_max.value))
		{
			if( parseInt(document.frmSearchAdvanced.txt_bedrooms_min.value) < parseInt(document.frmSearchAdvanced.txt_bedrooms_max.value) )
			{ return true; }
			else
			{
				alert ("Select minimum bedrooms less than maximum bedrooms.");
				document.frmSearchAdvanced.txt_bedrooms_min.style.border="1px solid #FF0000";
				document.frmSearchAdvanced.txt_bedrooms_max.style.border="1px solid #FF0000";
				document.frmSearchAdvanced.txt_bedrooms_min.focus();
				return false; 
			}
		}
		else
		if(trim(document.frmSearchAdvanced.txt_bedrooms_min.value) != "")
		{ return true; }
		else
		if(trim(document.frmSearchAdvanced.txt_bedrooms_max.value) != "")
		{ return true; }
		else
		if(trim(document.frmSearchAdvanced.txt_bathrooms_min.value) && trim(document.frmSearchAdvanced.txt_bathrooms_max.value))
		{
			if( parseInt(document.frmSearchAdvanced.txt_bathrooms_min.value) < parseInt(document.frmSearchAdvanced.txt_bathrooms_max.value) )
			{ return true; }
			else
			{
				alert ("Select minimum bathrooms less than maximum bathrooms.");
				document.frmSearchAdvanced.txt_bathrooms_min.style.border="1px solid #FF0000";
				document.frmSearchAdvanced.txt_bathrooms_max.style.border="1px solid #FF0000";
				document.frmSearchAdvanced.txt_bathrooms_min.focus();
				return false; 
			}
		}
		else
		if(trim(document.frmSearchAdvanced.txt_bathrooms_min.value) != "")
		{ return true; }
		else
		if(trim(document.frmSearchAdvanced.txt_bathrooms_max.value) != "")
		{ return true; }
		else
		if(is_checkboxes_checked(document.frmSearchAdvanced.chk_advance_current_housing))
		{ return true; }
		else
		if(is_checkboxes_checked(document.frmSearchAdvanced.chk_advance_move_timeframe))
		{ return true; }
		else
		if(is_checkboxes_checked(document.frmSearchAdvanced.chk_advance_pq_lender))
		{ return true; }
		else
		if(is_checkboxes_checked(document.frmSearchAdvanced.chk_sell_e_house))
		{ return true; }
		else
		{
			alert("Select atleast one filter to search clients records.");
			return false;
		}
  }
  else
  	return false
  
  return true;
 }
 
 function sumbitForm(frmName)
 {
	 document.frmName.submit();
 }
 
function validate_buildermail()
{
	var radioObj = document.frmSearch.txt_email_type;
	if(radioObj[1].checked == true && radioObj[1].value == "html")
		document.getElementById('txt_body').value=tinyMCE.getContent('txt_body');
		
	var req 		= new Array("txt_subject");
	var email 		= new Array();
	var digits 		= new Array();
	var currs 		= new Array();
	if(validate(req,email,digits,currs))
	{
		//if(tinyMCE.getContent('txt_body') == '')
		if(trim(document.getElementById('txt_body').value) == '')
		{
			alert("Please fill mail message.");
			return false;
		}//-- if.

		var obj = document.getElementById('txt_reply_to');
		if(trim(obj.value) != '')
		{
			if(!isEmail(obj.value))
			{
				alert("Please fill valid emails address for Reply To.");
				obj.focus();
				show_err_border("txt_reply_to");
				return false;
			}//-- if.
		}//-- if.
	}//-- if.
	else
		return false;
	
	return true;
}

function validateAgentMailingForm()
{
	if(document.getElementById('sel_desired_state').options[document.getElementById('sel_desired_state').selectedIndex].value == "")
	{
		alert("Please select agent state.");
		document.getElementById('sel_desired_state').style.border="1px solid #FF0000";
		document.getElementById('sel_desired_state').focus();
		return false;
	}
	else
	{
		if(document.frmSearch.chk_advance_desired_county)
		{
			if(!is_checkboxes_checked(document.frmSearch.chk_advance_desired_county))
			{
				alert("Please select county/counties.");
				return false;
			}
			else
			{
				var radioObj = document.frmSearch.txt_email_type;
				if(radioObj[1].checked == true && radioObj[1].value == "html")
					document.getElementById('txt_body').value=tinyMCE.getContent('txt_body');
			
				var req 		= new Array("txt_from_email","txt_subject");//-- 
				var email 		= new Array("txt_from_email");
				var digits 		= new Array();
				var currs 		= new Array();
				
				if(validate(req,email,digits,currs))
				{
					//alert(document.getElementById('txt_header').value + "\n" + is_radio_checked(document.frmSearch.header_radio_img) + "\n" + document.getElementById('txt_footer').value + "\n" + is_radio_checked(document.frmSearch.footer_radio_img));
					//if(tinyMCE.getContent('txt_body') == '')
					if(trim(document.getElementById('txt_body').value) == '' && isFieldIsEmpty(document.frmSearch.txt_header) == false  && isFieldIsEmpty(document.getElementById('txt_footer')) == false && is_radio_checked(document.frmSearch.header_radio_img) == false && is_radio_checked(document.frmSearch.footer_radio_img) == false)
					{
						alert("Please fill mail message.");
						return false;
					}//-- if.
			
					var obj = document.getElementById('txt_reply_to');
					if(trim(obj.value) != '')
					{
						if(!isEmail(obj.value))
						{
							alert("Please fill valid emails address for Reply To.");
							obj.focus();
							show_err_border("txt_reply_to");
							return false;
						}//-- if.
					}//-- if.
				}//-- if.
				else
					return false;
			}
		}
		else
		{
				alert("Please select county/counties.");
				return false;
		}
	}
	
	return true;
}

function isFieldIsEmpty(obj)
{
	if(!obj)	return false;
	
	if(trim(obj.value) == "") return false;
	
	return true;
}

//validates client status check login
function validateClientStatusCheckLogin(frm)
{	
	if(frm.txt_username.value == "")
	{
		alert("Please fill in username");
		frm.txt_username.focus();
		return false;
	}
	if(frm.txt_password_client_status.value == "")
	{
		alert("Please fill in password.");
		frm.txt_password_client_status.focus();
		return false ;
	}
	return true;	
}

function checkUrl(field)
{
     theUrl=field.value;
   //if(theUrl.match(/^(http)\:\/\/\w+([\.\-]\w+)*\.\w{2,4}(\:\d+)*([\/\.\-\?\&\%\#]\w+)*\/?$/i))
   if(theUrl.match(/http:\/\/[A-Za-z0-9\.\[\]\?-]{3,}\.[A-Za-z]{3}/))
      {
         //alert("valid address.");
         return true;
      }
    else
	if(theUrl.match(/https:\/\/[A-Za-z0-9\.\[\]\?-]{3,}\.[A-Za-z]{3}/))
		return true
	else
      {
         //alert("Wrong address.");
         //alert("Please fill in valid URL.");
         //field.style.border="1px solid #FF0000";
         //field.focus();
         return false;
      }
}    

function validateAddMultipleAccount(frm)
{
	var req 		= new Array("txt_builder_email_addr","txt_password");//,"txt_confirm_password"
	var email 		= new Array("txt_builder_email_addr");
	var digits 		= new Array();
	var currs 		= new Array();
	var res = validate(req,email,digits,currs);
	return res;
	/*if (res == false)
	{
		return res;
	}
	else
	if(trim(frm.txt_password.value) != trim(frm.txt_confirm_password.value))
	{
			alert("Password and Confirm password must be same.");
			frm.txt_password.focus();
			show_err_border("txt_password");
			show_err_border("txt_confirm_password");
			return false;
	}
	return true;*/
	
}