/**
 * Validates form elements.
 */
function validateForm(form) {
    var numberOfLivingRoomMin = 1;
    var numberOfLivingRoomMax = 6;
    var numberOfBedRoomMin = 1;
    var numberOfBedRoomMax = 9;
    var ageOfBuildingMin = 0;
    var ageOfBuildingMax = 30;
    var numberOfBathRoomMin = 1;
    var numberOfBathRoomMax = 6;
    var numberOfMasterBedRoomMin = 1;
    var numberOfMasterBedRoomMax = 9;
    var totalNumberOfParkingSpaceMin = 1;
    var totalNumberOfParkingSpaceMax = 999;
    var totalNumberOfFloorCondoMin = 1;
    var totalNumberOfFloorCondoMax = 100;
    var totalNumberOfFloorOfficeMin = 1;
    var totalNumberOfFloorOfficeMax = 99;
    var totalNumberOfFloorIndustrialMin = 1;
    var totalNumberOfFloorIndustrialMax = 100;
    var totalNumberOfBlockMin = 1;
    var totalNumberOfBlockMax = 50;
    var unitsPerFloorMin = 1;
    var unitsPerFloorMax = 40;
    var efficiencyRateMin = 0;
    var efficiencyRateMax = 100;
    var numberOfParkingSpaceMin = 1;
    var numberOfParkingSpaceMax = 9;
    var storeyMin = 1;
    var storeyMax = 5;
    var numberOfLiftsMin = 1;
    var numberOfLiftsMax = 9;
    var totalFloorMin = 1;
    var totalFloorMax = 9;
    
	var message_content = '\
       <div>\
  <div style="background-color: #CE0000; padding: 6px;">\
    <table width="98%" border="0" cellspacing="0" cellpadding="0"><tr><td><p style="color:#FFFFFF;"><b>\
	' + validation_alert +
	'\
	</b></p></td>\
        <td><div align="right"><input type="image" src="../../../../upload/images/cancel_button.gif" id="tel_agent_close" class="contact_agent_btn" width="21" height="21"></div></td></tr></table>\
    </div>\
	<div align="center" style="height:80px; margin-top: 10px; background-image: url(http://www.vproperty.mo/images/tel_agent_logo.png); background-position: right bottom; background-repeat: no-repeat">\
         <table width="98%" border="0" cellspacing="0" cellpadding="5" style="text-align:center;">\
        <tr>\
          <td>\
		  <p>\
    ';
	
	var message_content2 = '\
	</p>\
	 </td>\
        </tr>\
      </table>\
	  <p>&nbsp;</p>\
        </div>\
    </div>\
	';
	

	
    var result = true;
    var elements = form.elements;
    for (var i = 0; (i < elements.length) && result; ++i) {
        var element = elements[i];
        var nextSibling = element.nextSibling;
        if ((nextSibling != null) && (nextSibling.nodeType == 1) && (nextSibling.tagName == "A")) {
            //validate the field is not null
            if ((nextSibling.className == "nonempty") && (Trim(element.value) == "")) {
                alert({msg: message_content + "" + nextSibling.firstChild.nodeValue + cant_be_empty + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                element.focus();
                result = false;
            }

            //validate the field is not null nor too long
            if (nextSibling.className == "description") {
                if (Trim(element.value) == "") {
                    alert({msg: message_content + "" + nextSibling.firstChild.nodeValue + cant_be_empty + message_content2, show: "1", btn_cancel: "tel_agent_close" });
                    element.focus();
                    result = false;
                }
                else if (element.value.length > 255) {
                    alert({msg: message_content + "" + nextSibling.firstChild.nodeValue + " should be less than 255 characters." + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                    element.focus();
                    result = false;
                }
            }

            //no trainling blank character
            if ((nextSibling.className == "generalname") && !isGeneralName(element.value)) {
				alert({msg: message_content + "" + nextSibling.firstChild.nodeValue + " cannot begin/end with a blank character." + message_content2, show: "1", btn_cancel: "tel_agent_close" });
                element.focus();
                result = false;
            }

            //validate the field is not null or http://
            if ((nextSibling.className == "http") && ((Trim(element.value) == "") || (Trim(element.value) == "http://"))) {
                alert({msg: message_content + "" + nextSibling.firstChild.nodeValue + cant_be_empty + message_content2, show: "1", btn_cancel: "tel_agent_close" });
                element.focus();
                result = false;
            }

            //validate the field is mail format
            if ((nextSibling.className == "mailformat")) {
                var regstr = /^[\w-]+(\.[\w-]*)*@([\w-]+\.)+[\w-]{2,4}$/;
                if (!regstr.test(element.value) && element.value.length > 0) {
					alert({msg: message_content + "" + nextSibling.firstChild.nodeValue + wrong_email_format + message_content2, show: "1", btn_cancel: "tel_agent_close" });
                    element.focus();
                 result = false;
                }
            }

            //validate the field is URL format
            if ((nextSibling.className == "urlformat")) {
                var regstr = /^(http|https):\/\/([\w-]+\.)+[\w-]{2,4}(:\d+)?(\/[\w- .\/\?%&=]*)?$/;
                if (!regstr.test(element.value)) {
					alert({msg: message_content + "" + nextSibling.firstChild.nodeValue + " format is not a correct URL format." + message_content2, show: "1", btn_cancel: "tel_agent_close" });
                    element.focus();
                 result = false;
                }
            }

            //validate the field is date format
            if ((nextSibling.className == "dateformat")) {
                var reg  =  /^[0-9]{4}\-[0-9]{1,2}\-[0-9]{1,2}(\s[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2})?$/;
                result = (reg.test(element.value));
                if (!reg.test(element.value)) {
					alert({msg: message_content + "" + nextSibling.firstChild.nodeValue + " format is not a correct date format. For example 2005-7-3." + message_content2, show: "1", btn_cancel: "tel_agent_close" });
                    element.focus();
                    result = false;
                }
            }
            
            //validate the field is date format
            if ((nextSibling.className == "letter")) {
                var reg  =  /^[a-zA-Z0-9_]+?$/;
                result = (reg.test(element.value));
                if (!reg.test(element.value)) {
					alert({msg: message_content + "" + nextSibling.firstChild.nodeValue + " format is not a correct letter format, bounding a-z,A-Z,0-9,_. For example abc123_. " + message_content2, show: "1", btn_cancel: "tel_agent_close" });
					element.focus();
                    result = false;
                }
                else if(element.value.length < 3) {
					alert({msg: message_content + "" + nextSibling.firstChild.nodeValue + " is too short. It should at least contain 3 characters. " + message_content2, show: "1", btn_cancel: "tel_agent_close" });
                    element.focus();
                    result = false;
                }                
                else if(!isNaN(element.value.charAt(0)) || element.value.charAt(0) == "_") {
					alert({msg: message_content + "" + nextSibling.firstChild.nodeValue + " format is incorrect, the first character must be letter." + message_content2, show: "1", btn_cancel: "tel_agent_close" });
                    element.focus();
                    result = false;
                }
            }

            //validate the field is zip format
            if ((nextSibling.className == "zipcode")) {                
                var reg  = /^[+-]?[*0-9]+(\-[0-9]+)?$/;                
                if (!reg.test(element.value)) {
                    alert({msg: message_content + "" + nextSibling.firstChild.nodeValue + " format is not a correct zip code format. For example 12345-6789, or 12345." + message_content2, show: "1", btn_cancel: "tel_agent_close" });
					element.focus();
                    result = false;
                }
            }

            //validate the field is Code format
            if ((nextSibling.className == "code")) {                
                var reg  =  /^[0-9]+(\-[0-9]+)?$/;
                result = (reg.test(element.value));
                if (!reg.test(element.value)) {
					 alert({msg: message_content + "" + nextSibling.firstChild.nodeValue + " format is not a correct Code format." + message_content2, show: "1", btn_cancel: "tel_agent_close" });
                    element.focus();
                    result = false;
                }
            }
            
            //validate the field which is "SSN/Tax ID"
            if ((nextSibling.className == "ssn")) {                
                var reg = /[0-9]|[a-z]|[A-Z]|-/;
                var regNegative = /[\.]|[_]/;
                //var strLength = element.value.Length;
                result = (reg.test(element.value) && !regNegative.test(element.value));
                if (!reg.test(element.value) || regNegative.test(element.value) || element.value == "") {
					alert({msg: message_content + "The format of " + nextSibling.firstChild.nodeValue + " is not correct." + message_content2, show: "1", btn_cancel: "tel_agent_close" });
                    element.focus();
                    result = false;
                }
            }            
            
            //validate the field is float format
            if ((nextSibling.className == "floatformat")) {
                var regfloat  = /^[0-9]+(\.[0-9]+)?$/;
                if (!regfloat.test(element.value)) {
					alert({msg: message_content + "" + nextSibling.firstChild.nodeValue + require_positive_float + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                    
                    element.focus();
                    return false;
                }
                else if (element.value <= 0) {
                    alert({msg: message_content + nextSibling.firstChild.nodeValue + more_than_zero + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                    element.focus();
                    return false;
                }
            }
			
			 //validate the price field is float format
            if ((nextSibling.className == "pricefloatformat")) {
                var regfloat  = /^[0-9]+(\.[0-9]+)?$/;
                if (!regfloat.test(element.value)) {
					alert({msg: message_content + price_require_positive_float + nextSibling.firstChild.nodeValue + "<br/>" + rental_price_range + "<br/>" + sale_price_range + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                    
                    element.focus();
                    return false;
                }
                else if (element.value <= 0) {
                    alert({msg: message_content + price_require_positive_float + nextSibling.firstChild.nodeValue + "<br/>" + rental_price_range + "<br/>" + sale_price_range + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                    element.focus();
                    return false;
                }
            }
			
            //validate the field is optional float format
            if ((nextSibling.className == "optionalfloatformat")) {
                var regfloat  = /^[0-9]+(\.[0-9]+)?$/;
                if (!regfloat.test(element.value) && element.value.length > 0) {
					alert({msg: message_content + "" + nextSibling.firstChild.nodeValue + require_positive_float + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                    element.focus();
                    return false;
                }
                else if (element.value <= 0 && element.value.length > 0) {
					alert({msg: message_content + "" + nextSibling.firstChild.nodeValue + more_than_zero + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                    element.focus();
                    return false;
                }
            }
            
            //validate the field is money format
            if ((nextSibling.className == "moneyformat")) {
                var regfloat  = /^[0-9]+(\.[0-9]+)?$/;
                var letter = element.value;
                if (letter.substr(0,1) == "$") {
                    letter = letter.substr(1,letter.length-1);
                }
                else{
					alert({msg: message_content + "" + nextSibling.firstChild.nodeValue + " field must be a money format. For example $1.00!" + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                    return false;
                }
                
                if (!regfloat.test(letter)) {
					alert({msg: message_content + "" + nextSibling.firstChild.nodeValue + " field must be a money format. For example $1.00!" + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                    element.focus();
                    return false;
                }
                else if (letter <= 0) {
					alert({msg: message_content + "" + nextSibling.firstChild.nodeValue + more_than_zero + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                    element.focus();
                    return false;
                }
            }
            
            //validate the field is int format
            if ((nextSibling.className == "phone")) {
                var reg  =  /^[0-9*() \-]+(\-[0-9]+)?$/;
                result = (reg.test(element.value));
                if (!reg.test(element.value)) {
					alert({msg: message_content + 'Please input a phone!' + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                    element.focus();
                    return false;
                }
            }

            //validate the field is int format
            if ((nextSibling.className == "intformat")) {
                var regint  = /^[1-9][0-9]*$/;
                if (!regint.test(element.value)) {
					alert({msg: message_content + "" + nextSibling.firstChild.nodeValue + require_positive_int + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                    element.focus();
                    result = false;
                }
                else {                
                    if (element.intlength) {
                        var intlength = parseInt(element.intlength);
                        var max  = Math.pow(2,intlength);
                        if (parseFloat(element.value) > max-1) {
							alert({msg: message_content + "" + nextSibling.firstChild.nodeValue + too_big_input_again + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                            element.focus();
                            result = false;
                        }
                    }
                }
            }
			
			  //validate the field is sq ft int format
            if ((nextSibling.className == "sqftintformat")) {
                var regint  = /^[1-9][0-9]*$/;
                if (!regint.test(element.value)) {
					alert({msg: message_content + price_require_positive_float + nextSibling.firstChild.nodeValue + "<br/>" + sqft_require_positive_int + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                    element.focus();
                    result = false;
                }
                else {                
                    if (element.intlength) {
                        var intlength = parseInt(element.intlength);
                        var max  = Math.pow(2,intlength);
                        if (parseFloat(element.value) > max-1) {
							alert({msg: message_content + price_require_positive_float + nextSibling.firstChild.nodeValue + "<br/>" + sqft_require_positive_int + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                            element.focus();
                            result = false;
                        }
                    }
                }
            }
            
            if ((nextSibling.className == "int")) {
                var regint  = /^[1-9][0-9]*$/;
                if (!regint.test(element.value) && element.value.length > 0) {
					alert({msg: message_content + "" + nextSibling.firstChild.nodeValue + require_positive_int + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                   element.focus();
                    result = false;
                }
                else {                
                    if (element.intlength) {
                        var intlength = parseInt(element.intlength);
                        var max  = Math.pow(2,intlength);
                        if (parseFloat(element.value) > max-1) {
							alert({msg: message_content + "" + nextSibling.firstChild.nodeValue + too_big_input_again + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                            element.focus();
                            result = false;
                        }
                    }
                }
            }                                                                             
                                                            
            if ((nextSibling.className == "ageOfBuilding")) {
                var regfloat  = /^[0-9]+(\.[0-9]+)?$/;
                if ((!regfloat.test(element.value) || element.value > ageOfBuildingMax || element.value < ageOfBuildingMin ) && element.value.length > 0) {
					alert({msg: message_content + "" + nextSibling.firstChild.nodeValue + field_require_one + ageOfBuildingMin + "-" + ageOfBuildingMax + field_require_float + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                   element.focus();
                    result = false;
                }
                else {                
                    if (element.intlength) {
                        var intlength = parseInt(element.intlength);
                        var max  = Math.pow(2,intlength);
                        if (parseFloat(element.value) > max-1) {
							alert({msg: message_content + "" + nextSibling.firstChild.nodeValue + too_big_input_again + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                            element.focus();
                            result = false;
                        }
                    }
                }
            }
            
            if ((nextSibling.className == "efficiencyRate")) {
                var regfloat  = /^[0-9]+(\.[0-9]+)?$/;
                if ((!regfloat.test(element.value) || element.value >= efficiencyRateMax || element.value <= efficiencyRateMin ) && element.value.length > 0) {
					alert({msg: message_content + "" + nextSibling.firstChild.nodeValue + field_require_one + efficiencyRateMin + "-" + efficiencyRateMax + field_require_float + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                    element.focus();
                    result = false;
                }
                else {                
                    if (element.intlength) {
                        var intlength = parseInt(element.intlength);
                        var max  = Math.pow(2,intlength);
                        if (parseFloat(element.value) > max-1) {
							alert({msg: message_content + "" + nextSibling.firstChild.nodeValue + too_big_input_again + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                            element.focus();
                            result = false;
                        }
                    }
                }
            }                                                
                        
            if ((nextSibling.className == "numberOfLivingRoom")) {
                var regint  = /^[1-9][0-9]*$/;
                if ((!regint.test(element.value) || element.value > numberOfLivingRoomMax || element.value < numberOfLivingRoomMin) && element.value.length > 0) {
					alert({msg: message_content + "" + nextSibling.firstChild.nodeValue + field_require_one + numberOfLivingRoomMin + "-" + numberOfLivingRoomMax + field_require_int + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                    element.focus();
                    result = false;
                }
                else {                
                    if (element.intlength) {
                        var intlength = parseInt(element.intlength);
                        var max  = Math.pow(2,intlength);
                        if (parseFloat(element.value) > max-1) {
							alert({msg: message_content + "" + nextSibling.firstChild.nodeValue + too_big_input_again + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                            element.focus();
                            result = false;
                        }
                    }
                }
            }
                                    
            if ((nextSibling.className == "numberOfBedRoom")) {
                var regint  = /^[0-9][0-9]*$/;
                if (!regint.test(element.value) || element.value > numberOfBedRoomMax || element.value < numberOfBedRoomMin) {
					alert({msg: message_content + "" + nextSibling.firstChild.nodeValue + field_require_one + numberOfBedRoomMin + "-" + numberOfBedRoomMax + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                    element.focus();
                    result = false;
                }
                else {                
                    if (element.intlength) {
                        var intlength = parseInt(element.intlength);
                        var max  = Math.pow(2,intlength);
                        if (parseFloat(element.value) > max-1) {
                            alert({msg: message_content + nextSibling.firstChild.nodeValue + too_big_input_again + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                            element.focus();
                            result = false;
                        }
                    }
                }
            }
            
            if ((nextSibling.className == "numberOfBedRoomAdmin")) {
                var regint  = /^[1-9][0-9]*$/;
                if ((!regint.test(element.value) || element.value > numberOfBedRoomMax || element.value < numberOfBedRoomMin) && element.value.length >0) {
                    alert({msg: message_content + nextSibling.firstChild.nodeValue + field_require_one + numberOfBedRoomMin + "-" + numberOfBedRoomMax + field_require_int + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                    element.focus();
                    result = false;
                }
                else {                
                    if (element.intlength) {
                        var intlength = parseInt(element.intlength);
                        var max  = Math.pow(2,intlength);
                        if (parseFloat(element.value) > max-1) {
                            alert({msg: message_content + nextSibling.firstChild.nodeValue + too_big_input_again + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                            element.focus();
                            result = false;
                        }
                    }
                }
            }
                                    
            if ((nextSibling.className == "numberOfMasterBedRoom")) {
                var regint  = /^[1-9][0-9]*$/;
                if ((!regint.test(element.value) || element.value > numberOfMasterBedRoomMax || element.value < numberOfMasterBedRoomMin ) && element.value.length > 0) {
                    alert({msg: message_content + nextSibling.firstChild.nodeValue + field_require_one + numberOfMasterBedRoomMin + "-" + numberOfMasterBedRoomMax + field_require_int + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                    element.focus();
                    result = false;
                }
                else {                
                    if (element.intlength) {
                        var intlength = parseInt(element.intlength);
                        var max  = Math.pow(2,intlength);
                        if (parseFloat(element.value) > max-1) {
                            alert({msg: message_content + nextSibling.firstChild.nodeValue + too_big_input_again + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                            element.focus();
                            result = false;
                        }
                    }
                }
            }
            
            if ((nextSibling.className == "numberOfLifts")) {
                var regint  = /^[1-9][0-9]*$/;
                if ((!regint.test(element.value) || element.value > numberOfLiftsMax || element.value < numberOfLiftsMin ) && element.value.length > 0) {
                    alert({msg: message_content + nextSibling.firstChild.nodeValue + field_require_one + numberOfLiftsMin + "-" + numberOfLiftsMax + field_require_int + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                    element.focus();
                    result = false;
                }
                else {                
                    if (element.intlength) {
                        var intlength = parseInt(element.intlength);
                        var max  = Math.pow(2,intlength);
                        if (parseFloat(element.value) > max-1) {
                            alert({msg: message_content + nextSibling.firstChild.nodeValue + too_big_input_again + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                            element.focus();
                            result = false;
                        }
                    }
                }
            }
            
            if ((nextSibling.className == "totalNumberOfParkingSpace")) {
                var regint  = /^[1-9][0-9]*$/;
                if ((!regint.test(element.value) || element.value > totalNumberOfParkingSpaceMax || element.value < totalNumberOfParkingSpaceMin ) && element.value.length > 0) {
                    alert({msg: message_content + nextSibling.firstChild.nodeValue + field_require_one + totalNumberOfParkingSpaceMin + "-" + totalNumberOfParkingSpaceMax + field_require_int + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                    element.focus();
                    result = false;
                }
                else {                
                    if (element.intlength) {
                        var intlength = parseInt(element.intlength);
                        var max  = Math.pow(2,intlength);
                        if (parseFloat(element.value) > max-1) {
                            alert({msg: message_content + nextSibling.firstChild.nodeValue + too_big_input_again + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                            element.focus();
                            result = false;
                        }
                    }
                }
            }
            
            if ((nextSibling.className == "numberOfParkingSpace")) {
                var regint  = /^[1-9][0-9]*$/;
                if ((!regint.test(element.value) || element.value > numberOfParkingSpaceMax || element.value < numberOfParkingSpaceMin ) && element.value.length > 0) {
                    alert({msg: message_content + nextSibling.firstChild.nodeValue + field_require_one + numberOfParkingSpaceMin + "-" + numberOfParkingSpaceMax + field_require_int + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                    element.focus();
                    result = false;
                }
                else {                
                    if (element.intlength) {
                        var intlength = parseInt(element.intlength);
                        var max  = Math.pow(2,intlength);
                        if (parseFloat(element.value) > max-1) {
                            alert({msg: message_content + nextSibling.firstChild.nodeValue + too_big_input_again + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                            element.focus();
                            result = false;
                        }
                    }
                }
            }
            
            if ((nextSibling.className == "totalNumberOfFloorCondo")) {
                var regint  = /^[1-9][0-9]*$/;
                if ((!regint.test(element.value) || element.value > totalNumberOfFloorCondoMax || element.value < totalNumberOfFloorCondoMin ) && element.value.length > 0) {
                    alert({msg: message_content + nextSibling.firstChild.nodeValue + field_require_one + totalNumberOfFloorCondoMin + "-" + totalNumberOfFloorCondoMax + field_require_int + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                    element.focus();
                    result = false;
                }
                else {                
                    if (element.intlength) {
                        var intlength = parseInt(element.intlength);
                        var max  = Math.pow(2,intlength);
                        if (parseFloat(element.value) > max-1) {
                            alert({msg: message_content + nextSibling.firstChild.nodeValue + too_big_input_again + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                            element.focus();
                            result = false;
                        }
                    }
                }
            }
            
            if ((nextSibling.className == "totalNumberOfFloorOffice")) {
                var regint  = /^[1-9][0-9]*$/;
                if ((!regint.test(element.value) || element.value > totalNumberOfFloorOfficeMax || element.value < totalNumberOfFloorOfficeMin ) && element.value.length > 0) {
                    alert({msg: message_content + nextSibling.firstChild.nodeValue + field_require_one + totalNumberOfFloorOfficeMin + "-" + totalNumberOfFloorOfficeMax + field_require_int + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                    element.focus();
                    result = false;
                }
                else {                
                    if (element.intlength) {
                        var intlength = parseInt(element.intlength);
                        var max  = Math.pow(2,intlength);
                        if (parseFloat(element.value) > max-1) {
                            alert({msg: message_content + nextSibling.firstChild.nodeValue + too_big_input_again + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                            element.focus();
                            result = false;
                        }
                    }
                }
            }
            
            if ((nextSibling.className == "totalNumberOfFloorIndustrial")) {
                var regint  = /^[1-9][0-9]*$/;
                if ((!regint.test(element.value) || element.value > totalNumberOfFloorIndustrialMax || element.value < totalNumberOfFloorIndustrialMin ) && element.value.length > 0) {
                    alert({msg: message_content + nextSibling.firstChild.nodeValue + field_require_one + totalNumberOfFloorIndustrialMin + "-" + totalNumberOfFloorIndustrialMax + field_require_int + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                    element.focus();
                    result = false;
                }
                else {                
                    if (element.intlength) {
                        var intlength = parseInt(element.intlength);
                        var max  = Math.pow(2,intlength);
                        if (parseFloat(element.value) > max-1) {
                            alert({msg: message_content + nextSibling.firstChild.nodeValue + too_big_input_again + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                            element.focus();
                            result = false;
                        }
                    }
                }
            }
            
            if ((nextSibling.className == "totalFloor")) {
                var regint  = /^[1-9][0-9]*$/;
                if ((!regint.test(element.value) || element.value > totalFloorMax || element.value < totalFloorMin ) && element.value.length > 0) {
                    alert({msg: message_content + nextSibling.firstChild.nodeValue + field_require_one + totalFloorMin + "-" + totalFloorMax + field_require_int + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                    element.focus();
                    result = false;
                }
                else {                
                    if (element.intlength) {
                        var intlength = parseInt(element.intlength);
                        var max  = Math.pow(2,intlength);
                        if (parseFloat(element.value) > max-1) {
                            alert({msg: message_content + nextSibling.firstChild.nodeValue + too_big_input_again + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                            element.focus();
                            result = false;
                        }
                    }
                }
            }
                                    
            if ((nextSibling.className == "storey")) {
                var regint  = /^[1-9][0-9]*$/;
                if ((!regint.test(element.value) || element.value > storeyMax || element.value < storeyMin ) && element.value.length > 0) {
                    alert({msg: message_content + nextSibling.firstChild.nodeValue + field_require_one + storeyMin + "-" + storeyMax + field_require_int + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                    element.focus();
                    result = false;
                }
                else {                
                    if (element.intlength) {
                        var intlength = parseInt(element.intlength);
                        var max  = Math.pow(2,intlength);
                        if (parseFloat(element.value) > max-1) {
                            alert({msg: message_content + nextSibling.firstChild.nodeValue + too_big_input_again + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                            element.focus();
                            result = false;
                        }
                    }
                }
            }
            
            if ((nextSibling.className == "totalNumberOfBlock")) {
                var regint  = /^[1-9][0-9]*$/;
                if ((!regint.test(element.value) || element.value > totalNumberOfBlockMax || element.value < totalNumberOfBlockMin ) && element.value.length > 0) {
                    alert({msg: message_content + nextSibling.firstChild.nodeValue + field_require_one + totalNumberOfBlockMin + "-" + totalNumberOfBlockMax + field_require_int + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                    element.focus();
                    result = false;
                }
                else {                
                    if (element.intlength) {
                        var intlength = parseInt(element.intlength);
                        var max  = Math.pow(2,intlength);
                        if (parseFloat(element.value) > max-1) {
                            alert({msg: message_content + nextSibling.firstChild.nodeValue + too_big_input_again + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                            element.focus();
                            result = false;
                        }
                    }
                }
            }
            
            if ((nextSibling.className == "unitsPerFloor")) {
                var regint  = /^[1-9][0-9]*$/;
                if ((!regint.test(element.value) || element.value > unitsPerFloorMax || element.value < unitsPerFloorMin ) && element.value.length > 0) {
                    alert({msg: message_content + nextSibling.firstChild.nodeValue + field_require_one + unitsPerFloorMin + "-" + unitsPerFloorMax + field_require_int + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                    element.focus();
                    result = false;
                }
                else {                
                    if (element.intlength) {
                        var intlength = parseInt(element.intlength);
                        var max  = Math.pow(2,intlength);
                        if (parseFloat(element.value) > max-1) {
                            alert({msg: message_content + nextSibling.firstChild.nodeValue + too_big_input_again + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                            element.focus();
                            result = false;
                        }
                    }
                }
            }
                                    
            if ((nextSibling.className == "numberOfBathRoom")) {
                var regint  = /^[1-9][0-9]*$/;
                if ((!regint.test(element.value) || element.value > numberOfBathRoomMax || element.value < numberOfBathRoomMin ) && element.value.length > 0) {
                    alert({msg: message_content + nextSibling.firstChild.nodeValue + field_require_one + numberOfBathRoomMin + "-" + numberOfBathRoomMax + field_require_int + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                    element.focus();
                    result = false;
                }
                else {                
                    if (element.intlength) {
                        var intlength = parseInt(element.intlength);
                        var max  = Math.pow(2,intlength);
                        if (parseFloat(element.value) > max-1) {
                            alert({msg: message_content + nextSibling.firstChild.nodeValue + too_big_input_again + message_content2, show:"1", btn_cancel: "tel_agent_close" });
                            element.focus();
                            result = false;
                        }
                    }
                }
            }
        }
    }
    return result;
}

function convertToForm(containerId) {
  var form = document.createElement('FORM');
  var tempContainer = document.getElementById(containerId);
  var container = tempContainer.cloneNode(true);
  appendAllChildren(container, form);
  return form;
}

function validateContainer(containerId) {
  var form = convertToForm(containerId);
  return validateForm(form);
}

function appendAllChildren(node, container) {
  container.appendChild(node);
  var firstChild = node.firstChild;
  if (null != firstChild) {
    appendAllChildren(firstChild, container);
    var nextSibling = firstChild.nextSibling;
    while ( null != nextSibling) {
      appendAllChildren(nextSibling, container);
      nextSibling = nextSibling.nextSibling;
    }
  }
}

/**
 * Checks whether a character is blank (space, tab, or return).
 */
function isBlankCharacter(ch) {
    return (ch == ' ') || (ch == '\t') || (ch == '\r') || (ch == '\n');
}

/**
 * Checks whether a string is nonempty and has blank trailing (space, tab, or return).
 */
function isGeneralName(name) {
    return (name.length > 0) && !isBlankCharacter(name.charAt(0)) && !isBlankCharacter(name.charAt(name.length - 1));
}

/**
 * Deletes left space.
 */
function LTrim(str) {
    var whitespace = new String(" \t\n\r");
    var s = new String(str);
    if (whitespace.indexOf(s.charAt(0)) != -1) {
        var j = 0, i = s.length;
        while (j < i && whitespace.indexOf(s.charAt(j)) != -1) {
            j++;
        }
        s = s.substring(j, i);
    }
    return s;
}

/**
 * Deletes right space.
 */
function RTrim(str) {
    var whitespace = new String(" \t\n\r");
    var s = new String(str);
    if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
        var i = s.length - 1;
        while ((i >= 0) && (whitespace.indexOf(s.charAt(i)) != -1)) {
            i--;
        }
        s = s.substring(0, i+1);
    }
    return s;
}

/**
 * Deletes left and right space.
 */
function Trim(str) {
    return RTrim(LTrim(str));
}

/**
 * Gets year, month, day array by parsing date string.
 */
function getYMDDate(date, separator, sequence) {
    var dateArray = date.split(separator);
    var yearIndex = sequence.indexOf("y");
    var monthIndex = sequence.indexOf("m");
    var dayIndex = sequence.indexOf("d");
    var ymdArray = new Array(3);

    ymdArray[0] = dateArray[yearIndex];
    ymdArray[1] = dateArray[monthIndex];
    ymdArray[2] = dateArray[dayIndex];

    return ymdArray;
}