﻿var strContent
strContent = ''

function ValidateForm()
{

    var controlArray = document.forms[0].elements;
    var controlArrayLength = controlArray.length - 1;
    var controlId = '';
    var controlType = '';
    var questionId = '';
    var flag = true;
    var question = '';
    var alertMessage = '';
    
        for(i = 0; i < controlArrayLength; i++)
        {
            controlId = controlArray[i].id;   
             
                if( controlId.indexOf("isMandatory") > 0 )
	            {
	    	            if(controlArray[i].value == 'True')
                        {
                            controlType = document.getElementById(controlId.replace('isMandatory', 'Control')).value;
                            questionId = document.getElementById(controlId.replace('isMandatory', 'QuestionId')).value;
                            
                                  if(!CheckSelection(controlType, controlId, questionId))                                            
                                    {
                                        question = document.getElementById(controlId.replace('isMandatory', 'lblQuestion')).innerHTML;
                                        
                                        alertMessage = 'Please answer for question\n\n' + question;
                                        
                                        alert(alertMessage);
                                        
                                        return false;
                                        
                                      
                                        
                                    }//if(!CheckSelection(controlType, controlId)
                           }
                        
                   } //if(controlArray[i].value == 'False')
                    
	        }   //  if(controlId.indexOf("isMandatory") > 0)
    
    return true;
}

function CheckSelection(pControlType, pControlId, pQuestionId)
{

    var subControlId = '';
    var flag = false;
pControlType = pControlType.toLowerCase();

    if( pControlType == "checkbox")
    {
        for(j = 0; j <= 10; j++)
        {
            subControlId = pControlId.replace("isMandatory", "cbx") + j;
            var subControl = document.getElementById(subControlId);
            var subControlLabel = document.getElementById(subControlId.replace("cbx","lblcbx"));
            
            if(subControl != null)
            {
                //alert(subControl.value + ' - ' + subControlLabel.innerHTML.replace("<br>",""));
                if(subControl.checked)
                {
                    //strContent = strContent +  subControl.parentControl.innerHTML;
                    flag = true;
                    
                }   //  if(subControl.checked)
                
            }   //  if(subControl != null)   
            
        }   //  for(j = 0; j <= 10; j++)               
        
    } // if(controlType == "CheckBox")
    
    if(pControlType == "radiobutton")
    {
    
        for(j = 0; j <= 10; j++)
        {
            subControlId = pControlId.replace("isMandatory", "rbtn") + j;
            var subControl = document.getElementById(subControlId);
            var subControlLabel = document.getElementById(subControlId.replace("rbtn","lblrbtn"));
            
            if(subControl != null)
            {
                //alert(subControl.value + ' - ' + subControlLabel.innerHTML.replace("<br>",""));
                if(subControl.checked)
                {
                    //strContent = strContent +  subControl.parentControl.innerHTML;
                    flag = true;
                    
                }   //  if(subControl.checked)
                
            }   //  if(subControl != null)   
            
        }   //  for(j = 0; j <= 10; j++)               
        
    } // if(controlType == "CheckBox")
    
    if(pControlType == "listbox")
    {
        subControlId = pControlId.replace("isMandatory", "lbx" + pQuestionId);
        
        var subControl = document.getElementById(subControlId);
        
        //alert(subControl.selectedIndex);
        
        if(subControl.selectedIndex != -1)
        {
            flag = true;
        }
    }
    
    if(pControlType == "textbox")
    {
    
        subControlId = pControlId.replace("isMandatory", "tbx" + pQuestionId);
        
        var subControl = document.getElementById(subControlId);
        
        if(subControl.value != '')
            flag = true;
    }
    
    if(pControlType == "textarea")
    {
    
        subControlId = pControlId.replace("isMandatory", "tbxa" + pQuestionId);
        
        var subControl = document.getElementById(subControlId);
        
        if(subControl.value != '')
            flag = true;
    }
    
    if(pControlType == "dropdown")
    {
    
        subControlId = pControlId.replace("isMandatory", "ddl" + pQuestionId);
        
        var subControl = document.getElementById(subControlId);
        
       
        if(subControl.selectedIndex != 0)
        {
            flag = true;
        }
    }
    
    return flag;
}



         function setPosition_Header(pValue)
                {
                
                }
                
                
    function trim(str) {
	
		for( lspace=0 ; lspace<str.length ; lspace++ )
			if( str.charAt(lspace)!=' ' )
				break;
		str = str.substring( lspace );
		for( rspace=str.length-1 ; rspace>=0 ; rspace-- )
			if( str.charAt(rspace)!=' ' )
				break;
		str = str.substring( 0, rspace+1 );
		return str;
	}
	
	
function setToolTip(tbl)
{ 
    var DropDowns = tbl.getElementsByTagName('SELECT'); 
    
//    for ( var i = 0; i < DropDowns.length; i++ ) 
//    {
//            for ( j = 0; j < DropDowns[i].options.length;j++)
//            {
//              DropDowns[i].options[j].setAttribute('title',DropDowns[i].options[j].text); 
//              
//            } 
//    } 
}


//function OpenProfile(pServiceTypeId)
//    {
//        //alert(pServiceTypeId);
//        var rr  = window.open('../RegisterWithUs/UpdateProfile.aspx?ServiceTypeId='+pServiceTypeId ,"" ,'height=350, width=450, top=250, left=350, scrollbars=0, resizable=0');
//    }
    
    
function OpenProfile(pServiceTypeId, pClientId)
    {
        
        //var rr  = window.open('../RegisterWithUs/UpdateProfile.aspx?ServiceTypeId='+pServiceTypeId ,"" ,'height=350, width=450, top=250, left=350, scrollbars=0, resizable=0');

        var new_window = OpenPopupDailogwindow('../RegisterWithUs/UpdateProfile.aspx?ServiceTypeId=' + pServiceTypeId + '&Clientid=' + pClientId , '500','yes', 'no', 600,'200','300','', window);
        if ((new_window != '') && (new_window != 'undefined'))
        {
            //alert(new_window);
            Go_click_New(new_window);
        }
    } 
       
function OpenPopupDailogwindow(filename, iHeight,location, status, iWidth, iTop, iLeft, test, win)
    {
    
        var sFeatures = "dialogHeight: " + iHeight + "px; dialogWidth: " + iWidth + "px; dialogTop: " + iTop + "px; dialogLeft: " + iLeft + "px;  center:  yes ; help: no; resizable: no; status: " + status + "; location: " + location + " ";
        var tt = window.showModalDialog(filename, '', sFeatures);
                
        return tt
    } 
        
        