/////////////////////////////////HousingTrendsENewsLetter's Client Validation///////////////////


/***********************************
Clien Validation for Contact Me
***********************************/

function ClientsContact(frm){
	if(
	(ISNotNull(frm.subject,'Please Fill in the Subject') == true)
	&&
	(ISNotNull(frm.firstname,'Please Fill in your First Name') == true)
	&&
	(ISNotNull(frm.lastname,'Please Fill in your Last Name') == true)
	&&
	(ValidateEmailAddress(frm.email,'Please Fill in your Email Address') == true)
	&&
	(checkStrLen(frm.Message.value,'Please Fill in the Message (Message can not be more than 300 characters)', 299) == true)

	)//end if bracker
	{
		frm.submit();
	}//endif
}





/***********************************
Clien Validation for my Home Worth
***********************************/

function ClientsmyHomeWorth(frm){
	if(
	(ValidateAlpha(frm.FirstName,'Please Fill in your First Name') == true)
	&&
	(ValidateAlpha(frm.LastName,'Please Fill in your Last Name') == true)
	&&
	(ValidateEmailAddress(frm.Email,'Please Fill in your Email Address') == true)
	
	)//end if bracker
	{
		frm.submit();
	}//endif
}



/***********************************
Clien Validation for suscribe
***********************************/

function ClientSuscribe(frm){
	if(
	
	(ValidateEmailAddress(frm.Email,'Please Fill in your Email Address') == true)

	)//end if bracker
	{
		frm.submit();
	}//endif
}



/***********************************
Clien Validation for un suscribe
***********************************/

function clientUNSuscribe(frm){
	if(
	(ValidateAlpha(frm.FirstName,'Please Fill in your First Name') == true)
	&&
	(ValidateEmailAddress(frm.Email,'Please Fill in your Email Address') == true)
	)//end if bracker
	{
		frm.submit();
	}//endif
}



/***********************************
Clien Validation for un suscribe
***********************************/

function ClientEmailFriend(frm){
	if(
	(ValidateAlpha(frm.from,'Please Fill in your Name') == true)
	&&
	(ValidateEmailAddress(frm.to,'Please Fill in the recipent Email Address') == true)
	&&
	(ValidateAlpha(frm.name,'Please Fill in the recipent name') == true)
	&&
	(ISNotNull(frm.Comments,'Please Fill in the comments') == true)
	)//end if bracker
	{
		frm.submit();
	}//endif

}



////////////////////////Generic Functions start here//////////////////////////

/*
checks for credit card number (i.e. xxxx and 0-9) in a given string including length
Takes 2 strings as input first for checking and second errmsg
*/
function checkCCLenClient(alphane, str)
{

	if (alphane.length < 13){

		return false
	}
	else{

	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<59) || (hh == 120) )
		  {
		  }
		else	{
			alert(str + ' Please Check your Credit Card Number')
			 return false;
		  }
		}//end for
		 return true;
 }//end else
 
}//end function checknumericNLEN()








function ISNotNull(FieldName, msg)
{
	if (FieldName.value.length < 1 )
	{
		alert(msg);
		return (false);
	}
	else
	{
		return (true);
	}
}


/*
checks for field not to be null
Takes 1 strings as input first
*/

function ValidatorNull(FieldName)
{
	if (FieldName.value == "")
	{
		//alert(msg);
		//FieldName.focus();
		return (false);
	}
	else
	{
		return (true);
	}
}


/*
checks for Alpha and Number in a given string  ( Allowed : 0-9, A-Z, a-z )
Takes 2 strings as input first for checking and second errmsg
*/
/*
function checkNumericPhone(alphane, str)
{


if (alphane.length > 0 ){

	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<59) || (hh == 40) || (hh == 41) || (hh == 45) || (hh == 32))
		  {
		  }
		else	{
			alert(str + ' should only contains digits, (, ), -')
			 return false;
		  }
		}
 return true;
 }1
 else{
      alert('Please Check Your Phone Number');
      return false;
 }
}//end CheckNumericPhone()
*/





/*
checks for email address in a given string
Takes form field as input first for checking and second errmsg
*/
function ValidateEmailAddress(Field1Name,msg){

if (Field1Name.value.length > 0 ){

		var checkEmail = "@.";
		var checkStr = Field1Name.value;
		var EmailValid = false;
		var EmailAt = false;
		var EmailPeriod = false;
			for (i = 0;  i < checkStr.length;  i++)
				{
					ch = checkStr.charAt(i);
					for (j = 0;  j < checkEmail.length;  j++)
						{
						if (ch == checkEmail.charAt(j) && ch == "@")	EmailAt = true;
						if (ch == checkEmail.charAt(j) && ch == ".")	EmailPeriod = true;
						if (EmailAt && EmailPeriod)			break;
						if (j == checkEmail.length)			break;
						}
		
						if (EmailAt && EmailPeriod)
						{
						EmailValid = true
						break;
						}
				}
			if (!EmailValid)
				{
				alert(msg);
				Field1Name.focus();
				return (false);
				}
			else
				{
				return (true);
				}
		}
		else{
		Field1Name.focus();
		alert('Please Fill the email address');
		return false;
		}

}//end validateemailaddress()




/*
Checks for Alpha only 
Takes 2 strings as input first (form field) for checking and second errmsg
*/
function ValidateAlpha(FieldName,msg){

if (FieldName.value.length > 0 ){

	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ";
	var checkStr = FieldName.value;
	var allValid = true;
		for (i = 0;  i < checkStr.length;  i++)
			{
				ch = checkStr.charAt(i);
				for (j = 0;  j < checkOK.length;  j++)
				if (ch == checkOK.charAt(j))
				break;
					if (j == checkOK.length)
						{
						allValid = false;
						break;
						}
			}
		if (!allValid)
			{
				alert(msg);
				FieldName.focus();
				return false;
			}
		else
			{
			return true;
			}
	}
	else{
		alert(msg);
		return false;
	}

}//end validateAlpha


/*
Simply check the given input to be only of digits
Takes 2 strings as input first for checking and second errmsg
*/
function checkNumeric(alphane, str)
{


/*if (ValidatorNull(alphane) == true){*/
if (alphane.length > 0){

	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<59))
		  {
		  }
		else	{
			alert(str + ' should only contains digits')
			 return false;
		  }
		}
		 return true;
 
 	}
	else{
		alert(str);
		return false;
	}
}//end checkNumeric()






/*
checks for number in a given string including length
Takes 2 strings as input first for checking and second errmsg
*/
function checkNumericNLen(alphane, str)
{

	if (alphane.length < 13){

		return false
	}
	else{

	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<59))
		  {
		  }
		else	{
			alert(str + ' should only contains digits')
			 return false;
		  }
		}//end for
		 return true;
 }//end else
 
}//end function checknumericNLEN()






/*
checks for number in a given string including length
Takes 2 strings as input first for checking and second errmsg
*/
function chkNLen(alphane, str, len)
{

	if ( (alphane.length == len) ){
				var numaric = alphane;
		for(var j=0; j<numaric.length; j++)
			{
			  var alphaa = numaric.charAt(j);
			  var hh = alphaa.charCodeAt(0);
			  if((hh > 47 && hh<59))
			  {
			  }
			else	{
				alert(str + ' should only contains digits')
				 return false;
			  }
			}//end for
			 return true;
		}
	 else{
	 	alert(str);
		return false;
	 }
 
}//end function chkNLen()





/*
checks for phone number in a given string  ( allowed 0-9, (, ) , -, <space> )
Takes 2 strings as input first for checking and second errmsg
*/

function checkNumericPhone(alphane, str)
{


if (alphane.length > 0) {

	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<59) || (hh == 40) || (hh == 41) || (hh == 45) || (hh == 32))
		  {
		  }
		else	{
			alert(str + ' should only contains digits, (, ), -')
			 return false;
		  }
		}
 return true;
}

else{
	alert(str);
	return false;
}
}//end CheckNumericPhone()





/*
checks for string  in a given string 
Takes 3 strings as input first for checking, second errmsg and third length
*/

function checkStrLen(alphane, str, len)
{


	if (alphane.length > 0) {
		if( alphane.length > len){
			alert(str);
			return false;
		}
		else{
			return true;
		}
	}
	else{
		alert(str);
		return false;
	}

}//end checkStrLen()



/*
checks for string  in a given string 
Takes 3 strings as input first for checking, second errmsg and third length
*/

function checkCMOSelected(alphane, str)
{
	if ((alphane.value > 0) || (alphane.value == null)) {
		return true;
	}
	else{
		alert(str);
		return false;
	}

}//end checkMOSelected()



function checkZIP(alphane, str)
{

 if(alphane.length > 4 && alphane.length < 8){

	if ( (alphane.length > 7)){
		alert(str);
		return false
	}
	else{

	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<59))
		  {
		  }
		else	{
			alert(str + ' should only contains digits')
			 return false;
		  }
		}//end for
		 return true;
 }//end else
}
else{
	alert(str);
	return false; 
}
 
}//end function checkZIP()


////Generic Functions End HERe/////////////////////////////////////////////////
