var BeginningWhiteSpaceRegExp = /^\s+/;
var EndingWhiteSpaceRegExp = /\s+$/;


function CheckField(Required,WhichField,FieldType,DisplayName,ReqLength,Numeric) {
	var RegExp;
	var TestVal;
	var MatchChar;
	var ErrMsg = 'None';
		
	//Replace any whitespace at beginning and end of string with nothing	
	if (FieldType == 'Text' || FieldType == 'Alpha'  || FieldType == 'Date' || FieldType == 'Money' ||
		FieldType == 'MoneyWhole' || FieldType == 'Phone' || FieldType == 'Email' || FieldType == 'Website' || FieldType == 'Password') {
		TestVal = WhichField.value.replace(BeginningWhiteSpaceRegExp,'');
		TestVal = TestVal.replace(EndingWhiteSpaceRegExp,'');
	} else { 
		if (WhichField.selectedIndex == -1 || WhichField.options[WhichField.selectedIndex].value == 0) {
			TestVal = '';
		} else {	
			TestVal = WhichField.options[WhichField.selectedIndex].text;
		}
	}
	if (TestVal == '' && Required == true) {
		ErrMsg = DisplayName + ' must be entered';
	} 
	
	
	//If required check has been passed, continue with field type edits 
	
	if (ErrMsg == 'None' && TestVal != '') {	
		
		//Check required length 	
		if (ReqLength > 0) {
			if (TestVal.length != ReqLength) {
				ErrMsg = DisplayName + ' must be ' + ReqLength + ' characters';
			}
		}  
	
		//For money, remove all commas and one decimal, then set to Numeric to force numeric check
		if (FieldType == 'Money') {
			RegExp = /,/g;
			TestVal = TestVal.replace(RegExp,'');
			RegExp = /\./;
			TestVal = TestVal.replace(RegExp,'');
			Numeric = true;
		}
		
		//For money whole dollars, remove all commas then set to Numeric to force numeric check
		if (FieldType == 'MoneyWhole') {
			RegExp = /,/g;
			TestVal = TestVal.replace(RegExp,'');
			Numeric = true;
		}


		//Numeric check - match on any non-numeric character. If found, return Error.
		if (Numeric == true) {
			RegExp = /\D/;
			MatchChar = TestVal.match(RegExp);
			if (MatchChar != null) {
				ErrMsg = DisplayName + ' must be numeric';
			}
		}
	
		//Alpha check - match on any non A-Z character. If found, return Error.
		if (FieldType == 'Alpha') {
			RegExp = /[^A-Z]/;
			TestVal = TestVal.toUpperCase();
			MatchChar = TestVal.match(RegExp);
			if (MatchChar != null) {
				ErrMsg = DisplayName + ' must be alphabetic';
			}
		}
	
		//Check for valid date
		if (FieldType == 'Date') {
			if (CheckDate(TestVal) == 'Error') {
				ErrMsg = DisplayName + ' must be a valid date in mm/dd/yy format';
			}
		}
		
		//Check for valid Phone
		if (FieldType == 'Phone') {
			var c;
			var numLth=0;
			for(i=0;i<TestVal.length;i++) {
			    c=TestVal.charAt(i);
			    //Allow left bracket in 1st position only, and only if right bracked entered too, ie. (617)
			    if (c == '(') { 
					if (i==0 && TestVal.charAt(4) == ')') {
						continue;
					} else {
						ErrMsg = DisplayName + ' contains invalid brackets.';
						break;
					}
				} 
				
				//Allow right bracket in 5th position only ie. (617)
			    if (c == ')') {	
					if (i==4) {
						continue;
					} else {
						ErrMsg = DisplayName + ' contains invalid brackets.';
						break;
					}
				}
			    
			    if (c == ' ') {
					//Allow space only after area code right bracket
					if (i==5 && TestVal.charAt(4) == ')') {
						 continue; 
					} else {   
					   ErrMsg = 'Embedded spaces are not allowed in ' + DisplayName + '.\nUse hyphen, period, or comma to seperate numbers.';
					   break;
					}
			    }
			    
			    //Comma, hyphen or period allowed
			    if (c==',' || c=='-' || c==".") {
					continue;
				} else {
					if (isNaN(c)) {  
						ErrMsg = DisplayName + ' cannot have non-numeric digits.'; 
					    break;
					} else {
						numLth = numLth + 1;
					}
				}
			}
			
		}		
	
		//Check for valid email address
		if (FieldType == 'Email') {
			var no=0;
			var c;
    
			for(i=0;i<TestVal.length;i++) {
				c=TestVal.charAt(i);
			    if(i==0) { 
			        /*if(!isNaN(c)) {
						no=2;  
					}*/
				}
			    if(c==' ') no=2;
			    if(c =='@')  no++;
			}

			if(no!=1 || TestVal.indexOf('@')<2) {
				ErrMsg = TestVal + ' is not a valid E-mail Address';
			}
				   
			if (TestVal.indexOf('.')<1) {
				ErrMsg = TestVal + ' is not a valid E-mail Address';
			}
			
			if ((TestVal.length-TestVal.lastIndexOf('.'))<3) {
				ErrMsg = TestVal + ' is not a valid E-mail Address';
			}	
		}
		
		if (FieldType == 'Website') {
			var no=0;
			var c;
			if (TestVal.indexOf('.')<1) {
				ErrMsg = TestVal + ' is not a valid Website URL';
			}
			
			if ((TestVal.length-TestVal.lastIndexOf('.'))<3) {
				ErrMsg = TestVal + ' is not a valid Website URL';
			}	
		}
		
		
	}
	
	if (ErrMsg == 'None') {
		return('OK');
	} else {
		if (FieldType == 'List') {
			WhichField.selectedIndex = 0;
		}
		WhichField.focus();
		alert(ErrMsg);
		return('Error');
	} 
}



function CheckFieldWithoutFocus(Required,WhichField,FieldType,DisplayName,ReqLength,Numeric) {
	var RegExp;
	var TestVal;
	var MatchChar;
	var ErrMsg = 'None';
		
	//Replace any whitespace at beginning and end of string with nothing	
	if (FieldType == 'Text' || FieldType == 'Alpha'  || FieldType == 'Date' || FieldType == 'Money' ||
		FieldType == 'MoneyWhole' || FieldType == 'Phone' || FieldType == 'Email'|| FieldType == 'Password') {
		TestVal = WhichField.value.replace(BeginningWhiteSpaceRegExp,'');
		TestVal = TestVal.replace(EndingWhiteSpaceRegExp,'');
	} else { 
		if (WhichField.selectedIndex == -1 || WhichField.options[WhichField.selectedIndex].value == 0) {
			TestVal = '';
		} else {	
			TestVal = WhichField.options[WhichField.selectedIndex].text;
		}
	}
	if (TestVal == '' && Required == true) {
		ErrMsg = DisplayName + ' must be entered';
	} 
	
	
	//If required check has been passed, continue with field type edits 
	
	if (ErrMsg == 'None' && TestVal != '') {	
		
		//Check required length 	
		if (ReqLength > 0) {
			if (TestVal.length != ReqLength) {
				ErrMsg = DisplayName + ' must be ' + ReqLength + ' characters';
			}
		}  
	
		//For money, remove all commas and one decimal, then set to Numeric to force numeric check
		if (FieldType == 'Money') {
			RegExp = /,/g;
			TestVal = TestVal.replace(RegExp,'');
			RegExp = /\./;
			TestVal = TestVal.replace(RegExp,'');
			Numeric = true;
		}
		
		//For money whole dollars, remove all commas then set to Numeric to force numeric check
		if (FieldType == 'MoneyWhole') {
			RegExp = /,/g;
			TestVal = TestVal.replace(RegExp,'');
			Numeric = true;
		}


		//Numeric check - match on any non-numeric character. If found, return Error.
		if (Numeric == true) {
			RegExp = /\D/;
			MatchChar = TestVal.match(RegExp);
			if (MatchChar != null) {
				ErrMsg = DisplayName + ' must be numeric';
			}
		}
	
		//Alpha check - match on any non A-Z character. If found, return Error.
		if (FieldType == 'Alpha') {
			RegExp = /[^A-Z]/;
			TestVal = TestVal.toUpperCase();
			MatchChar = TestVal.match(RegExp);
			if (MatchChar != null) {
				ErrMsg = DisplayName + ' must be alphabetic';
			}
		}
	
		//Check for valid date
		if (FieldType == 'Date') {
			if (CheckDate(TestVal) == 'Error') {
				ErrMsg = DisplayName + ' must be a valid date in mm/dd/yy format';
			}
		}
		
		//Check for valid Phone
		if (FieldType == 'Phone') {
			var c;
			var numLth=0;
			for(i=0;i<TestVal.length;i++) {
			    c=TestVal.charAt(i);
			    //Allow left bracket in 1st position only, and only if right bracked entered too, ie. (617)
			    if (c == '(') { 
					if (i==0 && TestVal.charAt(4) == ')') {
						continue;
					} else {
						ErrMsg = DisplayName + ' contains invalid brackets.';
						break;
					}
				} 
				
				//Allow right bracket in 5th position only ie. (617)
			    if (c == ')') {	
					if (i==4) {
						continue;
					} else {
						ErrMsg = DisplayName + ' contains invalid brackets.';
						break;
					}
				}
			    
			    if (c == ' ') {
					//Allow space only after area code right bracket
					if (i==5 && TestVal.charAt(4) == ')') {
						 continue; 
					} else {   
					   ErrMsg = 'Embedded spaces are not allowed in ' + DisplayName + '.\nUse hyphen, period, or comma to seperate numbers.';
					   break;
					}
			    }
			    
			    //Comma, hyphen or period allowed
			    if (c==',' || c=='-' || c==".") {
					continue;
				} else {
					if (isNaN(c)) {  
						ErrMsg = DisplayName + ' cannot have non-numeric digits.'; 
					    break;
					} else {
						numLth = numLth + 1;
					}
				}
			}
			
		}		
	
		//Check for valid email address
		if (FieldType == 'Email') {
			var no=0;
			var c;
    
			for(i=0;i<TestVal.length;i++) {
				c=TestVal.charAt(i);
			    if(i==0) { 
			        /*if(!isNaN(c)) {
						no=2;  
					}*/
				}
			    if(c==' ') no=2;
			    if(c =='@')  no++;
			}

			if(no!=1 || TestVal.indexOf('@')<2) {
				ErrMsg = TestVal + ' is not a valid E-mail Address';
			}
				   
			if (TestVal.indexOf('.')<1) {
				ErrMsg = TestVal + ' is not a valid E-mail Address';
			}
			
			if ((TestVal.length-TestVal.lastIndexOf('.'))<3) {
				ErrMsg = TestVal + ' is not a valid E-mail Address';
			}	
		}

	}
	
	if (ErrMsg == 'None') {
		return('OK');
	} else {
		if (FieldType == 'List') {
			WhichField.selectedIndex = 0;
		}
		alert(ErrMsg);
		return('Error');
	} 
}


	
function trimSpaces(WhichField) {
	
	var TestVal;
	
	//Replace any whitespace at beginning and end of string with nothing	
	TestVal = WhichField.value.replace(BeginningWhiteSpaceRegExp,'');
	TestVal = TestVal.replace(EndingWhiteSpaceRegExp,'');
	
	return(TestVal);
}

function CheckDate(WhichDate) {
	
	var SplitStr;
	var SplitDate;
	var NumSplits;
	
	//Check for date separator either / or -
	SplitStr = WhichDate.indexOf("/");
	if (SplitStr == -1) {
		SplitStr = "-";
	} else {
		SplitStr = "/";
	}
	
	//Split by separator into mm dd yy
	SplitDate = WhichDate.split(SplitStr);
	NumSplits = SplitDate.length;
	if (NumSplits != 3) {
		return('Error');
	} else {
		mm = SplitDate[0];
		dd = SplitDate[1];
		yy = SplitDate[2];
	}
	
	if (yy.length != 2) {
		if(yy.length!=4){
			return('Error');
		}else{
			if (isNaN(yy) || yy<0  || yy>2100) return('Error');
		}
	}else{
		if (isNaN(yy) || yy<0  || yy>99) return('Error');
	}
			
	//basic error checking - check for number and proper range
	if (isNaN(mm) || mm<1  || mm>12) return('Error');
	if (isNaN(dd) || dd<1  || dd>31) return('Error');
	

	
	//advanced error checking

	// months with 30 days
	if (mm==4 || mm==6 || mm==9 || mm==11) {
		if (dd==31) return('Error');

	}

	// february, leap year
	if (mm==2) {
		if (dd>29) 	return('Error');

		if (dd==29) {
			if ((yy % 4 == 0 && yy % 100 != 0) || yy % 400 == 0) {
				return('OK');
			} else {
				return('Error');
			}
		}
	}
	return('OK');
}

function getMMDDCCYY(DateMMDDYY) {
	var Date1;
	var dd;
	var mm;
	var yr;
	Date1 = new Date(DateMMDDYY);
	dd = Date1.getDate();
	mm = Date1.getMonth();
	yr = Date1.getYear();
	if (yr > 0 && yr < 50) {
		yr = yr + 2000;
	}
	return (new Date(yr,mm,dd));
}

function MoveUpAndDown(selName,action,frmName)
{
	var lngLength = eval("document." + frmName + "." + selName + ".options.length");
	var ctrl = eval("document." + frmName + "." + selName);
	var i;
	var selCount;
	selCount = 0;
	
	
	//checking how many items are selected for movement.
	for (i = 0; i < lngLength; i++)  
		{
			if (ctrl.options[i].selected == true) 
			{
				selCount = selCount + 1;
			}
		}	
	
	//only one item can be selected for movement
	if (selCount == 0)
	{
		alert('No item is selected for movement.');
	} 
	else if (selCount > 1)
	{
		alert('Only one item can be selected for movement.');
	}
	else if (selCount == 1)
	{
	
		if (action == 'U')
		{
			funMoveUP(selName,frmName);
		}
		else if (action == 'D')
		{
			funMoveDown(selName,frmName); 
		}
	} 
}


function funMoveUP(strsctrlname,frmname)
{
//this function is used to move the options one step above.

	var object;				//store the object of the new option element
	var intidx;             //store the index of the selected option
	var objelement;         //stores the selected option element 
	var objsctrl = eval("document." + frmname + "." + strsctrlname);			//object of the selected drop down
	var arrmoveup;
	var intarrindex = 0;
	var intselectedidx;
	arrmoveup = new Array(); 
	
		if ( objsctrl.selectedIndex != -1 && objsctrl.selectedIndex > 0 )
		 {
			intselectedidx = objsctrl.selectedIndex;
			
			intarrindex = 0;
			if (intselectedidx > 0 )
			{
				for ( i = 0 ; i < objsctrl.length ; i ++ )
				{
					if ( i == intselectedidx - 1 )
					{
					arrmoveup[intarrindex]  = new Array();
					arrmoveup[intarrindex][0] = objsctrl[i+1].value;
					arrmoveup[intarrindex][1] = objsctrl[i+1].text;
					intarrindex = intarrindex + 1;
					}
					else if ( i == intselectedidx )
					{
					arrmoveup[intarrindex]  = new Array();
					arrmoveup[intarrindex][0] = objsctrl[i-1].value;
					arrmoveup[intarrindex][1] = objsctrl[i-1].text;
					intarrindex = intarrindex + 1;
					}
					else
					{
					arrmoveup[intarrindex]  = new Array();
					arrmoveup[intarrindex][0] = objsctrl[i].value;
					arrmoveup[intarrindex][1] = objsctrl[i].text;
					intarrindex = intarrindex + 1;
					}
					
				}
				
				objsctrl.length = 0;
				
				for ( i = 0 ; i < arrmoveup.length ; i++ )
				{
					objsctrl.options[i] = new Option( arrmoveup[i][1] , arrmoveup[i][0] )
				}
				
				objsctrl.selectedIndex = intselectedidx - 1 ;
					
			}	
			
		}	

}

function ValidateTextLength()
	{
			var strMandatoryMsg="More than 1024 characters are not allowed.";

		var strHdnCtrlList="";
		var arrHdnCtrlList="";
		var intCtrlCounter=0;
		var arrCtrlID;
		var strCtrlName="";
		var intSubCtrlCounter=0;
		var strCtrlType="";
		var intCtrlArrLength=0;
		var blnQuestionAnswered=false;
		var ctrl;
		
		
		
		if (document.frmParticipantInfo.hdnCtlrName == false) {
			return true	
		}
		
		strHdnCtrlList=document.frmParticipantInfo.hdnCtlrName.value;
		arrHdnCtrlList=strHdnCtrlList.split(",")
		
		for(intCtrlCounter=0;intCtrlCounter<arrHdnCtrlList.length;intCtrlCounter++) {
		
			strCtrlName=arrHdnCtrlList[intCtrlCounter]
			arrCtrlID = strCtrlName.split("_")
			strCtrlType=arrCtrlID[1]
			intCtrlArrLength=arrCtrlID[2]
			
			blnQuestionAnswered=false
			
			if ((strCtrlType=="TXT") || (strCtrlType=="TAR")) {
				
				ctrl=eval('document.frmParticipantInfo.'+strCtrlName);
				if (intCtrlArrLength>1) {
							
					for(intSubCtrlCounter=0;intSubCtrlCounter<intCtrlArrLength;intSubCtrlCounter++) {
												
						if (eval('document.frmParticipantInfo.'+strCtrlName+'['+intSubCtrlCounter+'].value.length')>1024) {
							alert(strMandatoryMsg)
							ctrl[intSubCtrlCounter].focus();	
							return false;
						}	
					
					}
					
				}else {
				
					if (eval('document.frmParticipantInfo.'+strCtrlName+'.value.length')>1024) {
						alert(strMandatoryMsg)
						ctrl.focus();	
						return false;
						
					}
					
				}
				
				
			}
		}			
	}
		

		
function ValidateMinTextLength(frmName,ctrlName,minilen)
	{
		var strMandatoryMsg=+ minilen +' or more characters are allowed.';

		var strHdnCtrlList="";
		var arrHdnCtrlList="";
		var intCtrlCounter=0;
		var arrCtrlID;
		var strCtrlName="";
		var intSubCtrlCounter=0;
		var strCtrlType="";
		var intCtrlArrLength=0;
		var blnQuestionAnswered=false;
		var blnNotBlank=false;
		var ctrl;
		
		
		if (eval(frmName+'.'+ctrlName) == false) {
			return true	
		}
		
		strHdnCtrlList=eval(frmName+'.'+ctrlName+'.value');
				
		arrHdnCtrlList=strHdnCtrlList.split(",")
	
		for(intCtrlCounter=0;intCtrlCounter<arrHdnCtrlList.length;intCtrlCounter++) {
	
			strCtrlName=arrHdnCtrlList[intCtrlCounter]
		
			
			if (eval(frmName+'.'+strCtrlName+'.length')>0)
			{
			var strCtrlNameIndex=""
				for (q=0;q<eval(frmName+'.'+strCtrlName+'.length');q++)						
				{	
					strCtrlNameIndex=frmName+'.'+strCtrlName+'['+q+']'
					
						arrCtrlID = strCtrlNameIndex.split("_")
						strCtrlType=arrCtrlID[1]
						intCtrlArrLength=arrCtrlID[2]
			
						blnQuestionAnswered=false
							
						if ((strCtrlType=="TXT") || (strCtrlType=="TAR")) {
							
							//ctrl=eval(frmName+'.'+strCtrlNameIndex);
							ctrl=eval(strCtrlNameIndex);
							
							if (intCtrlArrLength>1) {
								for(intSubCtrlCounter=0;intSubCtrlCounter<intCtrlArrLength;intSubCtrlCounter++) {
										{														
										if (eval(strCtrlNameIndex+'['+intSubCtrlCounter+'].value.length')<+ minilen ) {
											alert(strMandatoryMsg)
											ctrl[intSubCtrlCounter].focus();	
											return false;
										}	
									}
								}
								
							}else {
							
								var txtName=trimSpaces(eval(strCtrlNameIndex));
								if (txtName!=""){
									if ((txtName.length)<+ minilen ) {
										
										alert(strMandatoryMsg)
										ctrl.focus();	
										return false;
									}
										
								}
								if (blnNotBlank==false)
									{
									 blnNotBlank=true
									} 
								
							}
							
						  }
					
							
				}
				
				if (blnNotBlank==false)
				{
				alert("Please answer the mendatory question.")
				ctrl.focus();	
				return false;
				}
			
			}
			else
			{
			
				arrCtrlID = strCtrlName.split("_")
				strCtrlType=arrCtrlID[1]
				intCtrlArrLength=arrCtrlID[2]
				blnQuestionAnswered=false
			
				if ((strCtrlType=="TXT") || (strCtrlType=="TAR")) {
					
					ctrl=eval(frmName+'.'+strCtrlName);
					
					if (intCtrlArrLength>1) {
								
						for(intSubCtrlCounter=0;intSubCtrlCounter<intCtrlArrLength;intSubCtrlCounter++) {
												
							if (eval(frmName+'.'+strCtrlName+'['+intSubCtrlCounter+'].value.length')<+ minilen ) {
								alert(strMandatoryMsg)
								ctrl[intSubCtrlCounter].focus();	
								return false;
							}	
						
						}
						
					}else {
						var txtName=trimSpaces(eval(frmName+'.'+strCtrlName));
						if (txtName!=""){
							if ((txtName.length)<+ minilen ) {
								alert(strMandatoryMsg)
								ctrl.focus();	
								return false;
							}
						}
						
					}
				  }	
			}
		}	
		
	}
		

function ValidateAdditionalControl(frmName) {
	
		var strHdnCtrlList="";
		var arrHdnCtrlList="";
		var intCtrlCounter=0;
		var arrCtrlID;
		var strCtrlName="";
		var intSubCtrlCounter=0;
		var strCtrlType="";
		var intCtrlArrLength=0;
		var blnQuestionAnswered=false;
		var ctrl;
		var arrSubQuestionLen;
		var strSubQuestion;
		var strMandatoryMsg="Please answer the mandatory questions";
		var strParentQues
		var blnQuestionExist
		var ctrlFocus 
		
		if (document.getElementById("hdnAdditionalCtlrList") == false) {
			return true	
		}
		mstrConcatenate='$$'
		strHdnCtrlValue=document.getElementById("hdnAdditionalCtlrList").value;
		arrHdnCtrlValue=strHdnCtrlValue.split(",")
		var I
		for ( I=0;I<arrHdnCtrlValue.length;I++)
		{		
		arrCtrlName=arrHdnCtrlValue[I]
			
					arrControl=arrHdnCtrlValue[I].split(mstrConcatenate)
					strCtrlName=arrControl[0]
					strCtrlAnswer=arrControl[1]
					strCtrlType=arrControl[2]
					strAddCtrlName=strCtrlName + mstrConcatenate + strCtrlType
					
					strCtrlNameLen=eval(frmName+'.'+strCtrlName+'.length')
						for (k=0;k<strCtrlNameLen;k++)
						{
						
							if (eval(frmName+'.'+strCtrlName+'['+k+'].checked'))
							{
								if (eval(frmName+'.'+strCtrlName+'['+k+'].value')==+strCtrlAnswer)
								{	
									if (trimSpaces(eval('document.frmParticipantInfo.'+strAddCtrlName))=="")
									{
									alert('This field can not be left blank.')
									eval('document.frmParticipantInfo.'+strAddCtrlName+'.focus()');
									return false;	
									}
								}
							}
						}
					}
		}	
		

function ValidationSubQuestion() {
	
		var strHdnCtrlList="";
		var arrHdnCtrlList="";
		var intCtrlCounter=0;
		var arrCtrlID;
		var strCtrlName="";
		var intSubCtrlCounter=0;
		var strCtrlType="";
		var intCtrlArrLength=0;
		var blnQuestionAnswered=false;
		var ctrl;
		var arrSubQuestionLen;
		var strSubQuestion;
		var strMandatoryMsg="Please answer the mandatory questions";
		var strParentQues
		var blnQuestionExist
		var ctrlFocus 
	
		if (document.frmParticipantInfo.hdnParentCtlrList == false) {
			return true	
		}
		
		strHdnParentCtrlList=document.frmParticipantInfo.hdnParentCtlrList.value;
		arrHdnParentCtrlList=strHdnParentCtrlList.split(",")
		var I
		
		for ( I=0;I<arrHdnParentCtrlList.length;I++)
		{		
		
		strParentCtrlName=arrHdnParentCtrlList[I]
		
		strSubQuestion = eval('document.frmParticipantInfo.'+arrHdnParentCtrlList[I]+'.value')
		
		arrHdnCtrlList = strSubQuestion.split(",")
		
		blnQuestionExist=false
		strParentQues = arrHdnCtrlList[I]
		blnQuestionAnswered=false
		
				for(intCtrlCounter=0;intCtrlCounter<arrHdnCtrlList.length;intCtrlCounter++) {
					strCtrlName=arrHdnCtrlList[intCtrlCounter]
					arrCtrlID = strCtrlName.split("_")
					strCtrlType=arrCtrlID[1]
					intCtrlArrLength=arrCtrlID[2]
					
										
						if (strCtrlType=="OPT" || strCtrlType=="CHK" ) {
						   if (intCtrlArrLength>1) {
							
								for(intSubCtrlCounter=0;intSubCtrlCounter<intCtrlArrLength;intSubCtrlCounter++) {
															
									if (eval('document.frmParticipantInfo.'+strCtrlName+'['+intSubCtrlCounter+'].checked')==true) {
										blnQuestionAnswered=true
										
										break;
									}	
								
								}
							
							}else {
							
								if (eval('document.frmParticipantInfo.'+strCtrlName+'.checked')==true) {
									blnQuestionAnswered=true
									
								}
								
							}
							
						}else if ((strCtrlType=="TXT") || (strCtrlType=="TAR")) {
							if (blnQuestionAnswered!=true){
							
							if (trimSpaces(eval('document.frmParticipantInfo.'+strCtrlName))!="")
							{
								blnQuestionAnswered=true
								break;
							}
							
							
							}
							
						}else if ((strCtrlType=="DDL")) {
                           	if (eval('document.frmParticipantInfo.'+strCtrlName+'.selectedIndex')<1) {
								ctrl=eval('document.frmParticipantInfo.'+strCtrlName);
								ctrl.focus();

								alert(strMandatoryMsg);
								return false;
								
							}
                            blnQuestionAnswered=true
						}else if ((strCtrlType=="LST")) {
                           
							if (eval('document.frmParticipantInfo.'+strCtrlName+'.selectedIndex')==-1) {

								ctrl=eval('document.frmParticipantInfo.'+strCtrlName);
								ctrl.focus();
								alert(strMandatoryMsg);
								return false;
							}
						}
					}
					if (blnQuestionAnswered==false) {
					
						ctrl=eval('document.frmParticipantInfo.'+strCtrlName);
						if (intCtrlArrLength>1)
							ctrl[0].focus();	
						else
							ctrl.focus();
							
						alert(strMandatoryMsg);
						return false;
					
					}
								
			}
		}	
		
function ValidateQuestionnaire()
 {

		var strMandatoryMsg="Please answer the mandatory questions";

		var strHdnCtrlList="";
		var arrHdnCtrlList="";
		var intCtrlCounter=0;
		var arrCtrlID;
		var strCtrlName="";
		var intSubCtrlCounter=0;
		var strCtrlType="";
		var intCtrlArrLength=0;
		var blnQuestionAnswered=false;
		var ctrl;
		
		
		if (document.frmParticipantInfo.hdnCtlrList == false) {
			return true	
		}
		
		strHdnCtrlList=document.frmParticipantInfo.hdnCtlrList.value;
		arrHdnCtrlList=strHdnCtrlList.split(",")
		
		for(intCtrlCounter=0;intCtrlCounter<arrHdnCtrlList.length;intCtrlCounter++) {
		
			strCtrlName=arrHdnCtrlList[intCtrlCounter]
			arrCtrlID = strCtrlName.split("_")
			strCtrlType=arrCtrlID[1]
			intCtrlArrLength=arrCtrlID[2]
			blnQuestionAnswered=false
			
			if (strCtrlType=="OPT" || strCtrlType=="CHK") {
				if (intCtrlArrLength>1) {
				
					for(intSubCtrlCounter=0;intSubCtrlCounter<intCtrlArrLength;intSubCtrlCounter++) {
						if (eval('document.frmParticipantInfo.'+strCtrlName+'['+intSubCtrlCounter+'].checked')==true) {
							blnQuestionAnswered=true
							break;
						}	
					}
				
				}else {
				
					if (eval('document.frmParticipantInfo.'+strCtrlName+'.checked')==true) {
						blnQuestionAnswered=true
					}
					
				}
				
				if (blnQuestionAnswered==false) {
				
					ctrl=eval('document.frmParticipantInfo.'+strCtrlName);
					if (intCtrlArrLength>1)
						ctrl[0].focus();	
					else
						ctrl.focus();
						
					alert(strMandatoryMsg);
					return false;
				
				}
		
			}else if ((strCtrlType=="TXT") || (strCtrlType=="TNQ") || (strCtrlType=="TAR")) {
				if (intCtrlArrLength>1){
					//when more then one index of same control exist
					for(intSubCtrlCounter=0;intSubCtrlCounter<intCtrlArrLength;intSubCtrlCounter++) {
						if (trimSpaces(eval('document.frmParticipantInfo.'+strCtrlName+'['+intSubCtrlCounter+']')) != '') {
							blnQuestionAnswered=true
							break;
						}	
					}
					
						//display msg for this control
						if (blnQuestionAnswered==false) {
				
							ctrl=eval('document.frmParticipantInfo.'+strCtrlName);
							if (intCtrlArrLength>1)
								ctrl[0].focus();	
							else
								ctrl.focus();
								
							alert(strMandatoryMsg);
							return false;
						}
								
				}else
				{
				if (CheckField(true,eval('document.frmParticipantInfo.'+strCtrlName),'Text','Mandatory question',0,false) == 'Error') {
					blnQuestionAnswered=true;
					return false;
				}
				}
				
				
				
				
			}else if ((strCtrlType=="DDL")) {

				if (eval('document.frmParticipantInfo.'+strCtrlName+'.selectedIndex')<1) {

					ctrl=eval('document.frmParticipantInfo.'+strCtrlName);
					ctrl.focus();

					alert(strMandatoryMsg);
					return false;
					
				}

			}else if ((strCtrlType=="LST")) {

				if (eval('document.frmParticipantInfo.'+strCtrlName+'.selectedIndex')==-1) {

					ctrl=eval('document.frmParticipantInfo.'+strCtrlName);
					ctrl.focus();
					alert(strMandatoryMsg);
					return false;
				}
			}
		}
		
	}


function funMoveDown(strsctrlname,frmname)
{
//this function is used to move the options one step below.

	var object;						//store the object of the new option element
	var intidx;						//store the index of the selected option
	var objelement;                 //stores the selected option element 
	
	var objsctrl = eval("document." + frmname + "." + strsctrlname);		//object of the selected drop down
	var arrmovedown;
	var intarrindex = 0;
	var intselectedidx;
	arrmovedown = new Array(); 
	
		if ( objsctrl.selectedIndex != -1  )
		 {
			intselectedidx = objsctrl.selectedIndex;
			
			intarrindex = 0;
			if (intselectedidx < objsctrl.length - 1 )
			{
				
				for ( i = 0 ; i < objsctrl.length ; i ++ )
				{
					if ( i == intselectedidx + 1 )
					{
					arrmovedown[intarrindex]  = new Array();
					arrmovedown[intarrindex][0] = objsctrl[i-1].value;
					arrmovedown[intarrindex][1] = objsctrl[i-1].text;
					intarrindex = intarrindex + 1;
					}
					else if ( i == intselectedidx )
					{
					arrmovedown[intarrindex]  = new Array();
					arrmovedown[intarrindex][0] = objsctrl[i+1].value;
					arrmovedown[intarrindex][1] = objsctrl[i+1].text;
					intarrindex = intarrindex + 1;
					}
					else
					{
					arrmovedown[intarrindex]  = new Array();
					arrmovedown[intarrindex][0] = objsctrl[i].value;
					arrmovedown[intarrindex][1] = objsctrl[i].text;
					intarrindex = intarrindex + 1;
					}
					
				}
				
				objsctrl.length = 0;
				
				for ( i = 0 ; i < arrmovedown.length ; i++ )
				{
					objsctrl.options[i] = new Option( arrmovedown[i][1] , arrmovedown[i][0] )
				}
				
				objsctrl.selectedIndex = intselectedidx + 1 ;
					
			}	
			
		}	
	

}

function ValidateExtraQuestionLength(GuessImageValue)
{
	var txtBoxName=GuessImageValue //textbox name 
	var txtBoxValue=trimSpaces(GuessImageValue);// textbox value after trim 
	
	if (txtBoxValue.length<4)
	{
	alert('Minimum 4 characters are allowed')
	txtBoxName.focus();	
	return false;
	}	
	
	if (txtBoxValue.length>1024)
	{
	alert('More then 1024 characters are not allowed')
	txtBoxName.focus();	
	return false;
	}
return true;
}