﻿// JScript File
      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 getGuideType(obj,url)
             {
                var val = obj.options[obj.options.selectedIndex].value;
                if(val != -1)
                location.href=url+"&ddlGuideType="+val;                
             }
             
             
             
             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,"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) && chkPattern(obj,"area code",/^\d*[0-9]?$/)))
               {
                    return false;
               } 
                     
                obj = document.getElementById('txtContactNo');
               if(!(chkEmpty(obj,"contact number") && chkLength(obj,"Contact number",5,9) && chkPattern(obj,"contact number",/^\d*[0-9]?$/)))
               {
                    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;
               } 
               
              
         
                
                
               /*to check for buyerguides checkboxes */
             
                var checkSelected = false;

               var str = new String();
               
               var tempObj =  document.getElementById('checkboxnames');
               
               if(tempObj != null)
               {
                    
               
               
               str = tempObj.value;
               
     
               var arr = str.split(",");
               
               for (i = 0;  i < arr.length;  i++)
               {
               
               
               obj = document.getElementById(arr[i]);
               if(obj!=null)
               if (obj.checked)
                    checkSelected = true;
               
               }
               
               if (!checkSelected)
                 {
                 alert("Please select at least one of the Guides.");
               
                 return false;
                 }
               }
                 
                 return true;
              }