﻿// JScript File

function AddCommas(obj){
var B = obj.value;
B=B.replace(/,/g,"");
B+="";
x=B.split(".");
x1=x[0];
x2=x.length>1?"."+x[1]:"";
var A=/(\d+)(\d{3})/;
while(A.test(x1)){
x1=x1.replace(A,"$1,$2")
}
return obj.value=x1+x2;
}


      function fillCountryCode(obj)
      {
                var txtCountryCode = document.getElementById('txtContactCountryCode');
                if(obj.options[obj.options.selectedIndex].value != "-1")
                {
                  var Code = obj.options[obj.options.selectedIndex].value.split('-') ;
                  txtCountryCode.value = Code[2];
                }
                else
                {
                     txtCountryCode.value = "";
                }
             }
             function validateGE()
             {
               var obj = document.getElementById('ddltitle');
               if(obj.options[obj.options.selectedIndex].value == "-1")
               {
                         alert("Please select title");
                         obj.focus();
                         return false;
               }
                
                obj = document.getElementById('txtName');
               if(!(chkEmpty(obj,"first name") && chkLength(obj,"first name",3,25) && chkPattern(obj,"first name",/^\s*([A-Z]|[a-z])/)))
               {
                    return false;
               }               
               obj = document.getElementById('txtLastName');
               if(!(chkEmpty(obj,"last name") && chkLength(obj,"last name",3,25) && chkPattern(obj,"last name",/^\s*([A-Z]|[a-z])/)))
               {
                    return false;
               } 
                     
               obj = document.getElementById('ddlCountry');
               if(obj.options[obj.options.selectedIndex].value == "-1")
               {
                         alert("Please select country of residence");
                         obj.focus();
                         return false;
               }
                          
                obj = document.getElementById('txtContactAreaCode');
                if(!(chkEmpty(obj,"area code") && chkLength(obj,"area code",1,3)))
               {
                    return false;
               }
               else
               {
                        var filter  = /^\d*[0-9]?$/;
                        if(!filter.test(obj.value))
                        {
                            alert('Please check the format of your area code and ensure it has been entered correctly, no spaces or symbols');
                            return false;
                        }
               } 
                     
               obj = document.getElementById('txtContactNo');
               
               if(!(chkEmpty(obj,"contact number") && chkLength(obj,"contact number",5,9)))
               {
                    return false;
               } 
               else
               {
                        var filter  = /^\d*[0-9]?$/;
                        if(!filter.test(obj.value))
                        {
                            alert('Please check the format of your contact number and ensure it has been entered correctly, no spaces or symbols');
                            return false;
                        }
               } 
               
               obj = document.getElementById('txtEmail');
               if(!(chkEmpty(obj,"email address") && chkPattern(obj,"email address",/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/)))
               {
                    return false;
               } 
               
               
               obj = document.getElementById('ddlCity');
               if(obj.options[obj.options.selectedIndex].value == "-1")
               {
                         alert("Please select city");
                         obj.focus();
                         return false;
               }
               
               
               obj = document.getElementById('ddlDistrict');
               if(obj.options[obj.options.selectedIndex].value == "-1")
               {
                         alert("Please select district");
                         obj.focus();
                         return false;
               }
               
               
               obj = document.getElementById('ddlCommunity');
               if(obj.options[obj.options.selectedIndex].value == "-1")
               {
                         alert("Please select community");
                         obj.focus();
                         return false;
               }
               
               
               obj = document.getElementById('ddlSubcommunity');
               if(obj.options[obj.options.selectedIndex].value == "-1")
               {
                         alert("Please select subcommunity");
                         obj.focus();
                         return false;
               }
               
                
               obj = document.getElementById('ddlEnquiry');
               if(obj.options[obj.options.selectedIndex].value == "-1")
               {
                         alert("Please select enquiry about");
                         obj.focus();
                         return false;
               }
               
               obj = document.getElementById('ddlClientType');
               if(obj.options[obj.options.selectedIndex].value == "0" || obj.options[obj.options.selectedIndex].value == "5")
               {
                         alert("Please select client type");
                         obj.focus();
                         return false;
               }
              
                obj = document.getElementById('txtBudget');
                if(obj.value != "")
                {
                    var B = obj.value;
                    obj.value=obj.value.replace(/,/g,"");
                    if(!chkPattern(obj,"Budget",/^\d*[0-9]?$/))
                    {
                        obj.value = B;
                        return false;
                        
                    }
                    else
                    {
                        obj.value = B;
                    }
                }
               
                 return true;
            
                
             }
             function fillBudget(obj, enquiryTypeId,countryId,Path)
             {
                var txtObj = document.getElementById("hDivEnquiry");
                var rowObj = document.getElementById("rowBudget");
                var ddlObj = document.getElementById('ddlBudget');
                var txtBudgetObj = document.getElementById('txtBudget');
                if(obj.options[obj.options.selectedIndex].value != "-1" && obj.options[obj.options.selectedIndex].value != "Other" && obj.options[obj.options.selectedIndex].value != "Short-Term Rentals-3")
                {
                    txtObj.style.display ="none";
                    var URL = Path + "Search.aspx?type=Enquiry.budget&EnquiryTypeId="+enquiryTypeId+"&countryId="+countryId+"&EnquiryAboutId=" + obj.options[obj.options.selectedIndex].value;
                    CreateXmlHttpRequest();
                    var mydate = new Date();
                    URL+="&cacheId="+mydate.getTime();
                    request.onreadystatechange = fillBudgetValue;
                    request.open("GET", URL, true);
                    request.send(null);
                    var obj2 = document.getElementById('ddlBudget');
                    for(i=obj2.options.length -1; i >= 0; i--)
                    {
                        obj2.options[i] = null;
                    }
                    obj2.options[0] = document.createElement("option",true);
                    obj2.options[0].value = -1;
                    obj2.options[0].text = "Loading ...";
                    txtObj.style.display ="none";
                    txtBudgetObj.style.display ="none";
                    ddlObj.style.display ="block";
                    rowObj.style.display ="";                    
                    ddlObj.disabled='';
                  }
                     else if(obj.options[obj.options.selectedIndex].value == "Short-Term Rentals-3")
                     {
                        txtObj.style.display ="block";
                        rowObj.style.display ="";
                        
                        var k = 0;
                        for(k=ddlObj.options.length-1; k >= 0;k--)
                            {
                                ddlObj.options[k] = null;
                            }
                             ddlObj.disabled='';
                             ddlObj.style.display ="none";
                             txtBudgetObj.style.display ="block";
                     }
                     else if(obj.options[obj.options.selectedIndex].value == "Other")
                     {
                        rowObj.style.display ="none";
                        ddlObj.disabled='';
                        txtBudgetObj.style.display ="none";
                        ddlObj.style.display ="";
                     }
                      else if(obj.options[obj.options.selectedIndex].value == "-1")
                     {
                            var k = 0;
                            for(k=ddlObj.options.length-1; k >= 0;k--)
                            {
                                ddlObj.options[k] = null;
                            }
                            ddlObj.options[0] = document.createElement("option",true);
                            ddlObj.options[0].value = -1;
                            ddlObj.options[0].text = "Please select";
                            ddlObj.disabled='disabled';
                            rowObj.style.display ="";
                            txtBudgetObj.style.display ="none";
                            ddlObj.style.display ="block";
                     }
             }
