﻿        function submitForm(){
            if(validateForm()){
                document.getElementById('form1').submit();
            }
        }
        
        function validateForm(){
            var bOK=false;
            if(onlySave){
                bOK=true;
            }else{
                bOK=validatePage1();
                if(bOK){
                    bOK=validatePage4();
                }
            } 
            return bOK;
        }
        
        function validatePage1(){
            var bValid=true;
            var msg='';
            var bTest=false;
            
            if(isChecked('optPubOfRecord')){
                if(!hasValue('txtTellCompanyName')){
                    msg += 'Telephone company name is required\n';
                    bValid=false;
                } 
                if(!hasValue('txtTellCompanyContact')){
                    msg += 'Telephone company contact name is required\n';
                    bValid=false;
                } 
                if(!hasValue('txtTellCompanyPhone')){
                    msg += 'Telephone company phone number is required\n';
                    bValid=false;
                } 
                if(!hasValue('txtTellCompanyEmail')){
                    msg += 'Telephone company email is required\n';
                    bValid=false;
                } 
                //if(!hasValue('txtTellCompanyContract')){
                //   msg += 'Telephone company contract expires date is required\n';
                //    bValid=false;
                //} 
                if(!hasValue('txtTellCompanyAddress')){
                    msg += 'Telephone company address is required\n';
                    bValid=false;
                } 
                if(!hasValue('txtTellCompanyCity')){
                    msg += 'Telephone company city is required\n';
                    bValid=false;
                } 
                if(!hasValue('txtTellCompanyState')){
                    msg += 'Telephone company state is required\n';
                    bValid=false;
                } 
                if(!hasValue('txtTellCompanyZip')){
                    msg += 'Telephone company zip code is required\n';
                    bValid=false;
                } 
            }//isChecked('optPubOfRecord');
            
            var temp=document.getElementById('cboCategory').value;
            if(!temp=='CO'){
                if(!hasValue('cboSubFocus')&!hasValue('txtNewSubFocus')){
                    msg += 'With a Directory Category other than "Conventional" a sub-focus is required.\n';
                    bValid=false;
                } 
            }
            
            if(hasValue('cboCountry'))
            {
                temp=document.getElementById('cboCountry');
                if(temp=='US'||temp=='CA')
                { 
                    if(!hasValue('cboProvState')&!hasValue('txtNewState'))
                    {
                        msg += 'Directory State is required\n';
                        bValid=false;
                    }
                }
            }
            
            if((!isChecked('chkDirNew'))&&(!isChecked('chkDirCombined'))&&(!isChecked('chkDirSplit'))){
                msg += 'You must select a reason for the new Directory Code request.\n';
                bValid=false;
            }
            
            if(!hasValue('txtDirAbbrvName')){
                msg += 'Directory Abbreviated Name is required\n';
                bValid=false;
            }else{
                if(!hasValue('txtDirFullName')){
                    copyText('txtDirAbbrvName','txtDirFullName');
                } 
            }
            
            if(!hasValue('txtPublisherCode')){
                msg += 'Publisher Code is required\n';
                bValid=false;
            }
            
            if(!bValid){
                alert(msg);
            }
            return bValid;
        }
        
        function validatePage4(){
            var bValid=true;
            var msg='';
            
            if(!hasValue('txtPubContactName')){
                msg += 'You must enter a Contact Name.\n';
                bValid=false;
            }
            if(!hasValue('txtPubCompany')){
                msg += 'You must enter a Company Name.\n';
                bValid=false;
            }
            if(!hasValue('txtPubTelNumber')){
                msg += 'You must enter a Telephone Number.\n';
                bValid=false;
            }
            if(!hasValue('txtPubEmail')){
                msg += 'You must enter an Email Address.\n';
                bValid=false;
            }
            
            if(!bValid){
                alert(msg);
            }
            return bValid;
        }
        
        function hasValue(v){
            var t=document.getElementById(v);
            if(!t){
                alert('The request control "'+v+'" does not exist.');
            }else{
                var r=false;
                if(v){
                    if(t.value.length>0){
                        r=true;
                    } 
                }
            }
            return r;
        }
        
        function loadSubFocus(){
            var v=document.getElementById('cboCategory').value;
            var o=CodeRequest.LoadSubFocus(v).value;
            var str=  new String(o);
            var cbo=document.getElementById('cboSubFocus');
            
            //window.clearTimeout();
            //window.clearInterval();
            cbo.options.length=0;
            //cbo.options[0]=new Option('','');
            if(str.length){
                cbo.disabled=''
                var opts=str.split('~');
                for(var i=0;i<opts.length;i++){
                    var strVals=new String(opts[i]);
                    var vals=strVals.split(',');
                    cbo.options[i]=new Option(vals[1],vals[0]);
                 }
            }else{
                cbo.disabled='disabled'
                cbo.options.length=0;
                cbo.options.selectedIndex=-1; 
            }
            if(v=='CO'){
                document.getElementById('cboCountry').disabled='';
                document.getElementById('cboProvState').disabled='';
                document.getElementById('cboProvState').selectedIndex=0; 
                document.getElementById('cboCountry').value='US';
                document.getElementById('txtNewSubFocus').value='';
                hideThis('txtNewSubFocus');
            }else{
                document.getElementById('cboCountry').disabled='disabled';
                document.getElementById('cboProvState').disabled='disabled';
                document.getElementById('cboCountry').selectedIndex=-1;
                document.getElementById('cboProvState').selectedIndex=-1;
                document.getElementById('txtNewState').value='';
                document.getElementById('txtNewCountry').value='';
                hideThis('txtNewState');
                hideThis('txtNewCountry');
            }
        }
        
        function subfocusChange(v){
            if(v==''){
                showThis('txtNewSubFocus');
                focusThis('txtNewSubFocus');
            }else{
                hideThis('txtNewSubFocus');
                document.getElementById('txtNewSubFocus').value='';
            }
        }
        
        function newSubFocus_Blur(v){
            if(v==''){
                showThis('cboSubFocus');
                document.getElementById('cboSubFocus').selectedIndex=0;
                hideThis('txtNewSubFocus');
            }
        }
        
        function loadStates(){
            var v=document.getElementById('cboCountry').value;
            if(v==''){
               showThis('txtNewCountry');
               focusThis('txtNewCountry');
               document.getElementById('cboProvState').disabled='disabled';
               document.getElementById('cboProvState').selectedIndex=-1
               document.getElementById('txtNewState').disabled='disabled';
               document.getElementById('txtNewState').value='';
            }else{
               var cbo=document.getElementById('cboProvState');
               cbo.disabled='';
               document.getElementById('txtNewState').disabled='';
               document.getElementById('txtNewCountry').value='';
               hideThis('txtNewCountry');
               hideThis('txtNewState');
               var o=CodeRequest.LoadStates(v).value;
               var str=  new String(o);
               
               
               cbo.options.length=0;
               if(str.length){
                   cbo.disabled=''
                   var opts=str.split('~');
                   for(var i=0;i<opts.length;i++){
                       var strVals=new String(opts[i]);
                       var vals=strVals.split(',');
                       cbo.options[i]=new Option(vals[1],vals[0]);
                    }
               }else{
                    cbo.disabled='disabled'
                    cbo.options.length=0;
                    cbo.options.selectedIndex=-1;
               }
            }
        }        
        
        function stateChange(v){
            if(v==''){
                showThis('txtNewState');
               focusThis('txtNewState'); 
            }else{
                hideThis('txtNewState');
                document.getElementById('txtNewState').value='';
            }
        }
        
        function isNumber(evt){
            var charCode = (evt.which) ? evt.which : event.keyCode
            if (charCode > 31 && (charCode < 48 || charCode > 57)){
                return false;
            }else{
                return true;
            }
        }

    
        
