﻿// JScript File

       function formValidation()
       {
            var frm = document.forms[0];
            //var isvalidQ1 = true;
            var isvalidQ4 = true;
            var isvalidQ6 = true;
            var isvalidQ7 = true;
            var isvalidQ8 = true;
            var isvalidQ11 = true;
            
            var msg = '';
                
            //isvalidQ1 = Q1_Validation();
            isvalidQ4 = Q4_Validation();
            isvalidQ6 = Q6_Validation();
            isvalidQ7 = Q7_Validation();
            isvalidQ8 = Q8_Validation();
            isvalidQ11 = Q11_Validation();
                        
         
            if(isvalidQ4 == false)
            {
                msg = msg + '- Q4 has invalid answer.\r\n';
            }
            if(isvalidQ6 == false)
            {
                msg = msg + '- Q6 has invalid answer.\r\n';
            }
            if(isvalidQ7 == false)
            {
                msg = msg + '- Q7 has invalid answer.\r\n';
            }
            if(isvalidQ8 == false)
            {
                msg = msg + '- Q8 has invalid answer.\r\n';
            }
            if(isvalidQ11 == false)
            {
                msg = msg + '- Q11 has invalid answer.\r\n';
            }
            
            if(isvalidQ4 == true && isvalidQ6 == true && isvalidQ7 == true &&  isvalidQ8 == true &&isvalidQ11 == true)
            { 
                //document.getElementById('ErrorSummaryTr').style.display = "none"; 
                return true;                      
            } 
            else
            { 
                //document.getElementById('ErrorSummaryTr').style.display = "block"; 
                       
                alert(msg);
                return false;  
            } 
       } 
       //****************************************
       function Q6_Validation()
       {
            var frm = document.forms[0];
            var mySelection=new Array();
            var isvalid = true; 

            var c=0;
           
            for(i=0;i<frm.length; i++)
            {
                if(frm.elements[i].id.indexOf('q6_ddl') != -1)
                {                    
                    var Rankeditem = frm.elements[i];
                    
                    if(Rankeditem.selectedIndex != 0)
                    {
                        c++;
                        mySelection.push(Rankeditem.selectedIndex);
                    }
                 }                             
             } 
             
            if(c>3 || c<3)
            {
                isvalid = false;
                document.getElementById('Div6').style.visibility = "visible";                
            }
            else{
                var h=0;  
                for(m=0; m<mySelection.length; m++){
                        for(n=0; n<mySelection.length ; n++){
                            if(mySelection[m] == mySelection[n] && m != n){
                                h++;
                            }
                        }
                    } 
               
                if(h>0)
                   {
                        isvalid = false;
                        document.getElementById('Div6').style.visibility = "visible";                        
                   }
                   else 
                   {
                        isvalid = true;
                        document.getElementById('Div6').style.visibility = "hidden";                        
                   }            
            }
           
          return isvalid;
       }
       
              
       function Q4_Validation()
       {
            var isvalid = true;
            var col = document.getElementsByName("q4")
            var objTextBox = document.getElementById('q4_txt');
             
            for (i = 0 ; i < col.length ; i++) 
            {
                var el = col[i];
                if (el.type == "radio" && el.checked) 
                {
                    if(el.value == 1 && objTextBox.value.replace(' ', '').length == 0)
                    {
                              isvalid = false;            
                              document.getElementById('Div4').style.visibility = "visible";
                    }  
                    else
                    {
                              isvalid = true;
                              document.getElementById('Div4').style.visibility = "hidden";
                    }
                }                      
            }

           return isvalid;       
       
       }
       
       function Q7_Validation()
       {
            var frm = document.forms[0];
            var mySelection=new Array();
            var isvalid = true; 

            var c=0;
           
            for(i=0;i<frm.length; i++)
            {
                if(frm.elements[i].id.indexOf('q7_ddl') != -1)
                {                    
                    var Rankeditem = frm.elements[i];
                    
                    if(Rankeditem.selectedIndex != 0)
                    {
                        c++;
                        mySelection.push(Rankeditem.selectedIndex);
                    }
                 }                             
             } 
             
            if(c>3 || c<3)
            {
                isvalid = false;
                document.getElementById('Div7').style.visibility = "visible";                
            }
            else{
                var h=0;  
                for(m=0; m<mySelection.length; m++){
                        for(n=0; n<mySelection.length ; n++){
                            if(mySelection[m] == mySelection[n] && m != n){
                                h++;
                            }
                        }
                    } 
               
                if(h>0)
                   {
                        isvalid = false;
                        document.getElementById('Div7').style.visibility = "visible";                        
                   }
                   else 
                   {
                        isvalid = true;
                        document.getElementById('Div7').style.visibility = "hidden";                        
                   }            
            }
           
          return isvalid;
       }
       
       function Q11_Validation()
       {
            var isvalid = true;
            var col = document.getElementsByName("q11")
            var objTextBox = document.getElementById('q11_txt');
             
            for (i = 0 ; i < col.length ; i++) 
            {
                var el = col[i];
                if (el.type == "radio" && el.checked) 
                {
                    if(el.value == 1 && objTextBox.value.replace(' ', '').length == 0)
                    {
                              isvalid = false;            
                              document.getElementById('Div11').style.visibility = "visible";
                    }  
                    else
                    {
                              isvalid = true;
                              document.getElementById('Div11').style.visibility = "hidden";
                    }
                }                      
            }

           return isvalid;       
       
       }
       
        function Q8_Validation()
       {
            var isvalid = true;
            var col = document.getElementById("q8_12")
            var objTextBox = document.getElementById('q8_txt');
            
            if (col.type == "checkbox" && col.checked) 
                {
                    if(objTextBox.value.replace(' ', '').length == 0)
                    {
                              isvalid = false;            
                              document.getElementById('Div8').style.visibility = "visible";
                    }  
                    else
                    {
                              isvalid = true;
                              document.getElementById('Div8').style.visibility = "hidden";
                    }
                }                      
           

           return isvalid;       
}