

/**
 *  Function which get all childs inside of the specified DIV
 */
function getExactElementChain(tagname,stepNumber) {
	var elms = document.getElementById(tagname).getElementsByTagName('*');
	//For checkbox & radio we need to make sure we iterate only once
	var chkName='';
	//Global value which represents the form valid status.
	var isValid=true;
	for(var i = 0, maxI = elms.length; i < maxI; ++i) {
			var elm = elms[i];
			var type=elm.type;
			var name=elm.name;
			switch(type) {
				//case "reset"  "submit" "hidden" "image" "button" "file":
			  case "text":
			  case "textarea":
			  case "password":
			  case "select-one":
			  case "select-multiple":
			  case "radio":
			  case "checkbox":
				
				var name=elm.name;
				name=name.toLowerCase();
				var divEls = document.getElementById(name).getElementsByTagName('*');
				for(var j = 0, maxJ = divEls.length; j < maxJ; ++j){
				  var subElm = divEls[j];
				  //If this is the error field
				  if(subElm.id.indexOf('error') >= 0){
				    // Select, Text ,TextArea, Password Validation
					if(type=="text" || type=="textarea" || type=="password" || type=="select-one" || type==	"select-multiple" ){
					  document.getElementById(subElm.id).innerHTML='';
 				       if(isNull(elm.value) || "--- Select One ---" == elm.value){
							document.getElementById(subElm.id).innerHTML='Required Field';
							isValid=false;
					   }
					 }
					 //As we get all elemnts from checkboxgroup & Radio Group we want to check only one of them
					 if(( type=="checkbox" || type=="radio") && (chkName != name)){
						 document.getElementById(subElm.id).innerHTML='';
						 chkName=name;
						 if(type=="checkbox"){
							if(!validateRadioAndCheckBox(elm.name)){
							   document.getElementById(subElm.id).innerHTML='Required Field';
							   isValid=false;
							}
						 }
						 if(type=="radio"){
						    if(!validateRadioAndCheckBox(elm.name)){
							  document.getElementById(subElm.id).innerHTML='Required Field';
							  isValid=false;
						   }
						 }
					 }
				  }
		        }
			}
       }
     
     if(isValid){
		nextStep = stepNumber+1;
		ScrollSection('formPage-'+nextStep, 'scroller', 'formPage-0');
		
     }
     return isValid;
                                
 }

 /**
  * Checks the Radio Or Checkboix checked Or NOT
  */
 function validateRadioAndCheckBox(fieldName){
     var checked=false;
	 arr = document.getElementsByName(fieldName);
	 for(i=0; i < arr.length; i++){
		 if (arr[i].checked == true){
			checked = true;
			break;
		}
	}
	return checked;
 }
 /**
  * Checks the fields for the Null. Blank Or spaces 
  */
 function isNull(param){
       var fValue=param;
       if(fValue !=null){
           fValue = fValue.replace(/^\s+|\s+$/g, '') ;
           if(fValue =="" || fValue=="---" || fValue=='null'){
              return true;
           }
        }else{
            return true;
        }
        return false;
 }