
//This function is used to trim any string value using javascript.
function trimString (str) {
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}


//This function is used for email validation
function isValid(str) {

	var emailFilter=/^.+@.+\..{2,3}$/;
	if (!(str.match(emailFilter))) { 
        return false;
	}
	else {
		return true;
	}

}

//This function checks for illegal characters in the email
function isEmailUnwantedChars(emailId){
	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]\']/
	if (emailId.match(illegalChars)) {
		return true;
	}else{
		return false;
	}
}


//This function is used for Numeric values
function isNumeric(str) {
	var numFilter=/^[0-9][0-9]*$/;
	if (!(str.match(numFilter))) { 
        return false;
	}
	else {
		return true;
	}
}


//registration page Validations
//This function validate the following fields only. Please modify if adding more
  
function regValidate(docStr) {
	
	if( trimString(docStr.name.value) == "")	{
		alert("Please enter name!");
		docStr.name.focus();
		return false;
	}
	else if( trimString(docStr.address.value) == "")	{
		alert("Please enter address!");
		docStr.address.focus();
		return false;
	}
	else if( trimString(docStr.phoneNo.value) == "")	{
		alert("Please enter phoneNo!");
		docStr.phoneNo.focus();
		return false;
	}
	else if( trimString(docStr.parkCapacity.value) == "")	{
		alert("Please enter parkind capacity!");
		docStr.parkCapacity.focus();
		return false;
	}

	else if( trimString(docStr.rooms.value) == "" )	{
		alert("Please select the rooms !");
		docStr.rooms.focus();
		return false;
	}
	else if( trimString(docStr.bedRooms.value) == "" )	{
		alert("Please select the bedrooms  !");
		docStr.bedRooms.focus();
		return false;
	}
	else if( trimString(docStr.bathRooms.value) == "" )	{
		alert("Please select the bathrooms  !");
		docStr.bathRooms.focus();
		return false;
	}

	else if( trimString(docStr.livingLevel.value) =="" )	{
		alert("Please select the living level !");
		docStr.livingLevel.focus();
		return false;
	}
	else if( trimString(docStr.unitLevel.value) =="" )	{
		alert("Please enter the unit level !");
		docStr.unitLevel.focus();
		return false;
	}	
	else if( trimString(docStr.unitsInComplex.value) =="" )	{
		alert("Please enter the units In Complex !");
		docStr.unitsInComplex.focus();
		return false;
	}
	else if( trimString(docStr.desc.value) =="" )	{
		alert("Please enter the description !");
		docStr.desc.focus();
		return false;
	}
	else if( trimString(docStr.regDate.value) == "")	{
		alert("Please select any date!");
		return false;
	}
	
	else if( trimString(docStr.email.value) == "")	{
		alert("Please enter email ID!");
		docStr.email.focus();
		return false;
	}
	else if( !isValid( trimString(docStr.email.value) ) )	{
		alert("Please enter valid email ID!");
		docStr.email.focus();
		return false;
	}
	else {
		return true;
	}

}
