﻿// 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)
             {
                if(obj.options[obj.options.selectedIndex].value != "-1")
                {
                  var Code = obj.options[obj.options.selectedIndex].value.split('-') ;
                  var txtCountryCode = document.getElementById('txtContactCountryCode');
                  txtCountryCode.value = Code[2];
                }
                else
                {
                    document.getElementById('txtContactCountryCode').value="";
                }
             }
             
             function validate()
             {                             
               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,"family name") && chkLength(obj,"Family name",3,25) && chkPattern(obj,"Family 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") && chkLengthNew(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;
               } 
               
                 
                    
                if(!chkDates())
                {
                     return false;
                }
                return true;                
             }
             function chkDates()
             {
                var date1 = document.getElementById('dateFrom');
                var date2 = document.getElementById('dateTo');
                
                 if(date1.value =="Check-in date")
                {   
                    alert("Please select availibilty dates");
                    return false;
                }
                else if(date2.value =="Check-out date")
                {
                    alert("Please select availibilty dates");
                    return false;
                }
                var dateParts = date1.value.split("-");
                
                
                var dateChkIn = new Date(dateParts[2],dateParts[1],dateParts[0]);
                var dateParts = date2.value.split("-");
                var dateChkOut = new Date(dateParts[2],dateParts[1],dateParts[0]);
                
               
                if((((( (dateChkOut-dateChkIn) / 1000)/60)/60)/24) < 7)
                {
                   alert("Stay must be of 7 Days or more");
                   return false;
                }
                return true;
             }
             function fillSubLocations(obj,Path)
             {
               
                if(obj.options[obj.options.selectedIndex].value != "-1" && obj.options[obj.options.selectedIndex].value != "Not Specified|Not Specified")
                {
                    var stateId = obj.options[obj.options.selectedIndex].value.split('|');
                    var URL = Path + "Search.aspx?type=basic.community.selection&stateId=" +stateId[0];
                    CreateXmlHttpRequest();
                    var mydate = new Date();
                    URL+="&cacheId="+mydate.getTime();
                    request.onreadystatechange = fillBfillSubLocationsValue;
                    request.open("GET", URL, true);
                    request.send(null);
                    var obj2 = document.getElementById('divSubComm');
                    obj2.style.display="block"
                    obj2.innerHTML ="Loading .... "
                 }
                  else
                  {
                    var obj2 = document.getElementById('divSubComm');
                    obj2.style.display="none"
                  }

             }
             
           
             function fillBfillSubLocationsValue()
             {
                 if(request.readyState == 4)
                    {
                        if(request.status == 200)
                        {
                            var  FinalHTML = new String();
			                var obj = document.getElementById('divSubComm');
                            var newOptions = request.responseText.split("|");
                            for(i=0 ; i < newOptions.length ; i++)
                            {     var vals = newOptions[i].split("::");              
                                  FinalHTML += "<div style='height:20px;'>&nbsp;<input name='lstCommunity' type='Checkbox' value='"+vals[0]+"'/>&nbsp;"+vals[0]+"</div>";
                            }
                            obj.innerHTML = FinalHTML;
                        }
                        else
                        {
                            alert(request.status);
                        }
                    }
             }


