
function init(){
count=new Array(50);											//Arr from count of answers to each question

if(document.all){
	if(document.body.all.item("CheckSurvey")){
		var CheckboxNames=new Array();//Array from answers checkbox names
		var aInputs = document.all.item("CheckSurvey");
		for(i = 0; i<aInputs.length; i++){
		   CheckboxNames[i]=aInputs[i].name;
		}

		var QuestionsNames=new Array(); 							//Arr from inputs questions names
		var aQuestions = document.all.item("QuestionNumber");

		for(i = 0; i<aQuestions.length; i++){
		   QuestionsNames[i]=aQuestions[i].name;
		}

		for (i = 0; i < count.length; i++){
			count[i] = 0;
		}
		//start init accounting
		for (i=0; i<CheckboxNames.length; i++){
				if (eval("document.all." + CheckboxNames[i]) != null) {
					if (eval("document.all." + CheckboxNames[i] + ".checked") == true) {
						CurrentCheckboxName=CheckboxNames[i];
						posCH=eval("document.all." + CheckboxNames[i] + ".className")
						//CurrentQuestionName=CurrentCheckboxName.substring(1,posCH)
						count[posCH]+=1;
						//alert("count["+CurrentQuestionName + "]" + count[CurrentQuestionName]);
					}
				}
			}
		}

	}
	else {
		for (i = 0; i < count.length; i++){
			count[i] = 0;
		}
	}
}

//function countChoices(obj) {
//	var chName=obj.name;
//	var idx= chName.substring(chName.indexOf("ans")+3);
//
//	chName =eval("obj.form.q"+idx+".value") ; 		// max. number allowed at a time
//	var max= chName.substr(0,chName.indexOf(","));
//
//	idx=obj.className; //position of the Question within the survey
//
//	if (obj.checked){
//		alert(obj.name + "==" + count[idx])
//		count[idx]+=1;
//	}
//	else{
//		count[idx]-=1;
//	}
//	if (count[idx] > max) {
//		alert("You can only choose up to " + max + " choices! \nUncheck an option if you want to pick anoth.");
//		obj.checked = false;
//		count[idx]-=1;
//	}
//
//}
function countChoices(obj) {
	var chName=obj.name;
	var idx= chName.substring(chName.indexOf("ans")+3);
	var j=0;

	chName =eval("obj.form.q"+idx+".value") ; 		// max. number allowed at a time
	var max= chName.substr(0,chName.indexOf(","));

	var aChoices = new Array();
	if (document.all.item("ans" + idx)) aChoices=document.all.item("ans" + idx);
	for (i=0; i<aChoices.length; i++){
		if (aChoices[i].checked){
			j+=1;
		}
	}
	if (j > max){
		alert("You can only choose up to " + max + " choices! \nUncheck an option if you want to pick anoth.");
		obj.checked = false;
	}

}


function srvGoto(sCll){

	sURL="admin.asp?uri=" + sCll;
	document.frmSurveyAnswer.action= sURL;
	document.frmSurveyAnswer.submit();
}

function CheckAdd(val){
	if (isNumFunction(val.value) == false) {
		alert('The value in the field must be number');//TODO Other VALIDATIONS!!!
		val.value='';
	}
}
function CheckEmail(val)
{
	if (val.value.indexOf ('@',0) == -1 || val.value.indexOf ('.',0) == -1)  {
            alert("Please enter a valid e-mail address.");
            val.value='';
    }
}

/* This is the old version of the function that doesn't support Other (Specify) answer types
function valRequired(){ //Required check
	var sRtn='';
	var aQuestions = new Array();
	if (document.all.item("QuestionNumber")) aQuestions=document.all.item("QuestionNumber");

	for(var i = 0; i<aQuestions.length; i++){
		var qVal=aQuestions[i].value;
		var qName=aQuestions[i].name;
		var qTitle=aQuestions[i].className;
		var row = aQuestions[i].row;

		var req= qVal.substring(qVal.indexOf(",")+1);
		if (req=='True'){ //required answer
			var idx=qName.substring(qName.indexOf("q")+1);
			chName =eval("document.all.ans"+idx); //undefined when no Qtype/choices are defined
			if (typeof(chName)!='undefined'){
				if (typeof(chName.length)!="undefined"){//check for checked/selected items
					var sEmpty='true';
					for (var j=0; j<chName.length; j++ ){
						if (chName[j].checked || chName[j].selected){ sEmpty=''; break; }
					}
					if (sEmpty!=''){
						alert ('Please, select an answer for ' + qTitle); sRtn='break';
						if (chName.type!=undefined) chName.focus(); else chName[0].focus();
						break;
					}
				}
				else { //text/Textarea
					if (chName.value==''){
						if (IsAnswerEntry(row)!=''){
						alert ('Please, enter ' + qTitle); chName =eval("document.all.ans"+idx); chName.focus(); sRtn='break'; break;
						}
					}
				}
			}
		}
	}
	return sRtn;
}
*/

//This is the new version of the function that does support Other (Specify) answer types
function valRequired(){ //Required check
	var sRtn='';
	var sErrMsg='';
	var aQuestions = new Array();


//  Changed by Spas in April,2010 - document.all doesn't work in Netscape based browsers (FF, Chrome, Opera)
//	if (document.all.item("QuestionNumber")) aQuestions=document.all.item("QuestionNumber");
//	if (document.all.item("QuestionNumber")) aQuestions=document.getElementsByName("QuestionNumber");

	aQuestions=document.getElementsByTagName("input");

	for(var i = 0; i<aQuestions.length; i++){
		if(aQuestions[i].id == "QuestionNumber"){
			var qVal=aQuestions[i].value;
			var qName=aQuestions[i].name;
			var qTitle=aQuestions[i].className;
			var row = aQuestions[i].getAttribute('row');
			var qType = aQuestions[i].getAttribute('qtype');

			var req= qVal.substring(qVal.indexOf(",")+1);
			if (req=='True'){ //required answer
				var idx=qName.substring(qName.indexOf("q")+1);
//				chName =eval("document.all.ans"+idx);
				//chName = document.getElementById("ans"+idx);
				chName = document.getElementsByName("ans"+idx);
				if(chName.length==1) chName = chName[0];
//				alert("ans"+idx+"; typeof: " + typeof(chName)+ "; typeof length: " + typeof(chName.length) + "; qtype: " + qType + "; row: " + row);
				if (typeof(chName)!='undefined'){
					if (typeof(chName.length)!='undefined')
					{
						var sEmpty='true';
						for (var j=0; j<chName.length; j++ )
						{
							var aVal = chName[j].value;
							var objID	= "ans"+idx+"other"+aVal;
							var otherSpecify = document.getElementById(objID);

							if (chName[j].checked || chName[j].selected)
								{
									if (otherSpecify != null)
										{
											var osVl = otherSpecify.value;
											if (osVl == '' || osVl == null)
												{
													sEmpty='true';
												}
											else
												{
													sEmpty='';
												}
										}
									else
										{
											sEmpty='';
										}
								}
						}
						if (sEmpty!=''){
							//alert ('Please, select an answer for ' + qTitle); sRtn='break';
							sErrMsg = sErrMsg + '\t' + qTitle + '\n';
							if (chName.type!=undefined) chName.focus(); else chName[0].focus();
							//break;
						}
					}
					else if ((qType == 3) || (qType == 10))
					{
						var sEmpty2='true';
						var bSelcted;
						var aVal2 = chName.value;
						var objID2	= "ans"+idx+"other"+aVal2;
						var otherSpecify2 = document.getElementById(objID2);

//alert("Object: " + chName + "; Value: " + chName.value + "; Checked: " + chName.checked + "; Selected: " + chName.selected);
						if(chName.checked)
						{
							bSelcted = 'true';
						}
						else if(chName.selected)
						{
							bSelcted = 'true';
						}
						else
						{
							bSelcted = 'false';
						}

						if(bSelcted == 'true')
						{
							if (otherSpecify2 != null)
								{
									var osVl2 = otherSpecify2.value;
									if (osVl2 == '' || osVl2 == null)
										{
											sEmpty2='true';
										}
									else
										{
											sEmpty2='';
										}
								}
							else
								{
									sEmpty2='';
								}
						}

						if (sEmpty2!=''){
							//alert ('Please, select an answer for ' + qTitle); sRtn='break';
							sErrMsg = sErrMsg + '\t' + qTitle + '\n';
							chName.focus();
							//break;
						}
					}
					else { //text/Textarea
						if (chName.value==''){
							if (IsAnswerEntry(row)!=''){
								//alert ('Please, enter ' + qTitle);
								sErrMsg = sErrMsg + '\t' + qTitle + '\n';
//								chName =eval("document.all.ans"+idx);
								chName = document.getElementById("ans"+idx);
								chName.style.backgroundColor="#FFFF33";
								chName.focus();
								sRtn='break';
								//break;
							}
						}
						else
							{
//								chName =eval("document.all.ans"+idx);
								chName = document.getElementById("ans"+idx);
								chName.style.backgroundColor="";
							}
					}
				}
			}
		}
	}

	if(sErrMsg != '')
	{
		alert('Please enter a value for each of the following questions: \n\n' + sErrMsg);
		return 'err';
	}
	else
	{
		return '';
	}
}


function IsAnswerEntry(chkrow)
	{
	//alert(chkrow);
	var aQst = new Array();
	var aChoice = new Array();
	var ans='';

//	if (document.all.item("QuestionNumber")) aQst=document.all.item("QuestionNumber");
	aQst=document.getElementsByTagName("input");

	for(var i = 0; i<aQst.length; i++){
		if(aQst[i].id == "QuestionNumber"){
			var row = aQst[i].getAttribute('row');
			var qName=aQst[i].name;
			var qtype =aQst[i].getAttribute('qtype');

			var idx=qName.substring(qName.indexOf("q")+1);
//			chName =eval("document.all.ans"+idx); //undefined when no Qtype/choices are defined
			chName = document.getElementById("ans"+idx);

			if (chkrow==row){
				if (qtype == 3)	{
					for (var j=0; j<chName.length; j++ ){
					if (chName[j].checked || chName[j].selected){ans='exit';}
					}
				}
				else if(qtype != 6) {
					if (chName.value!='' || chName.value!=null) {
						if (chName.value!=0 || chName.value!=null) {
							ans='exist';
						}
					}
				}
			}
		}
	}
	return  ans;
}

function submitSrv(frmAction){
	//Requiered check
	if (valRequiredExtended('frmSurveyAnswer')==''){
		document.frmSurveyAnswer.action=frmAction;
		document.frmSurveyAnswer.submit();
	}
}


function CheckChoice(cbo, maxAns, sQuestion){
	var ans=0;
	var ind=new Array();
	if(typeof(sQuestion)=='undefined') sQuestion='';
	else sQuestion= ' for "' + sQuestion + '"';
	for (var i=0;i<cbo.length;i++){
		if (cbo[i].selected) {ans++; ind[ans]=i; }
	}
	if(ans>maxAns){ alert('You can only choose up to ' + maxAns + ' choices' + sQuestion + '! \nUncheck an option if you want to select another.');
		var j=0; //unselect the choices > maxAnswers
		for(var i=maxAns; i<ans; i++){
			cbo[ind[ans-j]].selected=false;
			j++; }
		}
}


//-----------------------------
function showHidePayMethods(val, DBvalue){
	onChangeElement();

	if (val.value!='choice' && DBvalue=='choice'){
		var msgConfirm=confirm("You are about to change question type. Existing choices will be deleted.");
		if (msgConfirm!=true) {

		for(i=0; i<document.frmManage.QuestType.length;i++){
			if (document.frmManage.QuestType(i).value=='choice')
				{
				document.frmManage.QuestType(i).checked=true;
				return;
				}
			}
		}
	}

	showHideLayers('Predifined','hide');
 	if (val.value==1){
 		showHideLayers('TxtOption','show');
  		showHideLayers('ChoiceOption','hide');
  		showHideLayers('SubOption','hide');
	}
	if (val.value==3){
		showHideLayers('ChoiceOption','show')
 		showHideLayers('TxtOption','hide');
 		showHideLayers('SubOption','hide');
	}
	if (val.value==2){
		showHideLayers('ChoiceOption','hide');
 		showHideLayers('TxtOption','hide');
 		showHideLayers('SubOption','hide');
	}
	if (val.value==4){
		showHideLayers('ChoiceOption','hide');
 		showHideLayers('TxtOption','hide');
  		showHideLayers('Predifined','show')
  		showHideLayers('SubOption','hide');
	}
	if (val.value==5){
		showHideLayers('ChoiceOption','hide');
 		showHideLayers('TxtOption','hide');
  		showHideLayers('Predifined','hide')
  		showHideLayers('SubOption','show');
	}
	if (val.value==6){
		showHideLayers('ChoiceOption','hide');
 		showHideLayers('TxtOption','hide');
 		showHideLayers('SubOption','hide');
	}
	if (val.value==10){
		showHideLayers('ChoiceOption','hide');
 		showHideLayers('TxtOption','hide');
 		showHideLayers('SubOption','hide');
	}
	if (val.value==11){
		showHideLayers('ChoiceOption','hide');
 		showHideLayers('TxtOption','hide');
 		showHideLayers('SubOption','hide');
	}
}

function showHideLayers(ID,v){
	if(document.getElementById(ID)!=null) document.getElementById(ID).style.display=(v=='show')?'':'none';
	}

function _onEnter(){	}

function _OnKeyUp(si,qi,cll, btn){
var sURL="";

sURL="admin.asp?uri=2020&action=4&si=" + si + "&qi=" + qi + "&goto=-10";
if (cll!='') {
sURL = sURL + "&cll=" + cll;
}

if(window.event.keyCode==13 || btn==1){
	frmManage.action = sURL;
	frmManage.submit();
	}
}

function checkSendEmail(rid, bSubForm, id){ //frmManage / forms(0)
	if (bSubForm!=-1) bSubForm=0;
	document.frmManage.action ="admin.asp?uri=2334&action=2&id=" + rid + "&email=yes&obj=" + bSubForm + "&eid=" + id;
	document.frmManage.submit();
}



function LookUp(id,rowUpd, bSts, GoToAction){

if(typeof(GoToAction)=='undefined') GoToAction=2;
if(typeof(step)=='undefined') step=0;

var gotoUrl='&state=goto&goto=2021|fi=1|cll=2334|action=' + GoToAction+ '|id=' + id + '|row=' + rowUpd;
if (GoToAction==1) gotoUrl= gotoUrl + "|st=4";


if (bSts!='True'){
	_onSave(document.frmManage,'2334&action=4&id=' + id + '&row=' + rowUpd + gotoUrl);
	}
else{
	frmManage.action=frmManage.action+ '&row=' + rowUpd + gotoUrl;
	frmManage.submit();
	}
}

// LookUp to Question ProductCode/ ProductName
function ProdSrch(id,QID, bSts, GoToAction){

if(typeof(GoToAction)=='undefined') GoToAction=2;
if(typeof(step)=='undefined') step=0;

var gotoUrl='&state=goto&goto=2021|fi=1|cll=2334|action=' + GoToAction+ '|id=' + id + '|qd=' + QID;
if (GoToAction==1) gotoUrl= gotoUrl + "|st=4";

if (bSts!='True'){
	_onSave(document.frmManage,'2334&action=4&id=' + id + '&qd=' + QID + gotoUrl);
	}
else{

	frmManage.action='admin.asp?uri=2334&action=4&id='+ id + '&qd=' + QID + gotoUrl;
	frmManage.submit();
	}
}

//CurUrl - 2334 RequestMng/AdminEntry; CurUrl - 1083 RequestPublicEntry/RequestQuote
function RemoveFormRow(CurUrl, bSts, Rqid, RTid, row,Act){
var URLgoto="";
var UrlSave="";
var SaveAction=4;
var msgConfirm = confirm("Are you sure you want to delete this item?");

if (msgConfirm) {
		URLgoto='&remove='+ row + '&state=goto&goto='+ CurUrl + '|id=' + Rqid;
		if (CurUrl==2334){URLgoto = URLgoto + '|action='+ Act;}
		if (CurUrl==1083 && Act!=1){URLgoto = URLgoto + '|action='+ Act;}
		if (CurUrl==2334){URLgoto = URLgoto + '|st=4';}
		if (CurUrl==4001){SaveAction =44; URLgoto= URLgoto + '|st=11'; }

		if (bSts!='True'){

			if(Rqid <= 0)
				{
				UrlSave= CurUrl + '&action=' + SaveAction + '&rid=' + RTid + URLgoto;
				}
			else
				{UrlSave= CurUrl + '&action=' + SaveAction + '&id=' + Rqid + URLgoto;}

			if (CurUrl==2334 || CurUrl==4001){UrlSave='admin.asp?uri=' + UrlSave + '&st=11';}
			else {UrlSave='main.asp?uri=' + UrlSave;}

		//	alert(UrlSave);
			document.frmManage.action=UrlSave;
			document.frmManage.submit();
		}
		else{
		//	alert(frmManage.action + URLgoto);
			document.frmManage.action=frmManage.action + URLgoto;
			document.frmManage.submit();
		}
	}
}

//CurUrl - 2334 RequestMng/AdminEntry; CurUrl - 1083 RequestPublicEntry/RequestQuote
function AddFormRow(CurUrl, bSts, Rqid, RTid, row,Act){
var URLgoto="";
var UrlSave="";
var SaveAction=4;

URLgoto='&add='+ row + '&state=goto&goto='+ CurUrl + '|id=' + Rqid;
if (CurUrl==2334){URLgoto = URLgoto + '|action='+ Act;}
if (CurUrl==1083 && Act!=1){URLgoto = URLgoto + '|action='+ Act;}
if (CurUrl==2334){URLgoto = URLgoto + '|st=4';}
if (CurUrl==4001){SaveAction =44; URLgoto= URLgoto + '|st=11'; }

if (bSts!='True'){

	if(Rqid <= 0)
		{
		UrlSave= CurUrl + '&action=' + SaveAction + '&rid=' + RTid + URLgoto;
		}
	else
		{UrlSave= CurUrl + '&action=' + SaveAction + '&id=' + Rqid + URLgoto;}

	if (CurUrl==2334 || CurUrl==4001){UrlSave='admin.asp?uri=' + UrlSave + '&st=11';}
	else {UrlSave='main.asp?uri=' + UrlSave;}

	document.frmManage.action=UrlSave;
	document.frmManage.submit();
}
else{
	document.frmManage.action=frmManage.action + URLgoto;
	document.frmManage.submit();
}
}


function Raise_Events(){
	ClearAnswers("input");
	ClearAnswers("select");
	ClearAnswers("textarea");
	var selObj=document.getElementById("Existing");
	var selValue=selObj.options[selObj.selectedIndex].value; //the value of the selected option from <select>
	if(selValue==0) return;
	var hiddenCntrl=document.getElementById("DB_Ans"+ selValue); //the needed hidden control depending on the selected option
	var controls=hiddenCntrl.value.substring(0,hiddenCntrl.value.length-1).split(";"); //array of all ### sections from the hidden control
	var equalIndex; //index of '=' in each ### section
	var controlName; //the value between 'Q' and 'Data' => if we have Q71Data or Q71Choices the result is 71
	var controlObj; //array of elements with same controlName
	var controlValue; //the value after each 'Q[something here]Choices='
	for(var i=1; i<controls.length; i=i+2){
		equalIndex=controls[i].indexOf("=")
		controlName=controls[i].substring(4,equalIndex-7);
		controlValue=controls[i].substring(equalIndex+1,controls[i].length)
		if(controlValue==""){
			if(document.getElementsByName("ans" + controlName).length==1){
				controlObj=document.getElementsByName("ans" + controlName)[0];
				controlValue=controls[i-1].substring(controls[i-1].indexOf("=")+1,controls[i-1].length);

				switch(controlObj.type){
					case "text" :
						controlObj.value=controlValue;
						break;
					case "textarea" :
						controlObj.value=controlValue;
						break;
				}
			}
		}
		else{
			if(document.getElementsByName("ans" + controlName).length >0){
				controlObj=document.getElementsByName("ans" + controlName);
				for(var j=0; j<controlObj.length; j++){
					switch(controlObj[j].type){
						case "select-one" :
							for(var k=0; k<controlObj[j].length; k++){
								if(controlObj[j].options[k].value==controlValue*1) controlObj[j].options[k].selected=true;
							}
							break;
						case "radio" :
							if(controlObj[j].value==controlValue*1) controlObj[j].checked=true;
							break;
						case "checkbox" :
							var mulValues=controlValue.split(",");
							for(var singleVal in mulValues){
								if(controlObj[j].value==mulValues[singleVal]*1) controlObj[j].checked=true;
							}
							break;
					}
				}
			}
		}
	}
}


function ClearAnswers(tag){
	var answers=document.getElementsByTagName(tag);
	for(var i=0; i<answers.length; i++){
		if(answers[i].name.match("\ans")){
			switch(answers[i].type){
				case "text" :
					answers[i].value=""
					break;
				case "textarea" :
					answers[i].value=""
					break;
				case "select-one" :
					answers[i].selectedIndex=0;
					break;
				case "radio" :
					answers[i].checked=false;
					break;
				case "checkbox" :
					answers[i].checked=false;
					break;
			}
		}
	}
}

function _CopyQuestion(si,qi){
var sURL="";

sURL="admin.asp?uri=2020&action=4&si=" + si + "&qi=" + qi + "&copycalled=1";

frmManage.action = sURL;
frmManage.submit();
}

function SetLinkToContact(val){
	var obj=document.getElementById('LinkToContact');
	if(obj){
		obj.options.length=0;
		if(val.indexOf(',')>0) val=val.substring(0,val.indexOf(','));
		//alert(val);
		switch(val*1){
			case 1:
			case 29:
			case 30:
			case 31:
			case 32:
			case 33:
			case 34:
			case 35:
			case 9:
			case 6:
			case 46:
					document.getElementById('divOrdersLbl').style.display='none';
					document.getElementById('divReqLbl').style.display='none';
					document.getElementById('divLinkToContact').style.display='';
					obj.options[0]=new Option("Linked to Contact", "1", false, true);
					obj.options[1]=new Option("Not Linked to Contact", "6", false, false);
					break;
			case 2:
			case 4:
			case 3:
			case 5:
			case 36:
			case 37:
			case 38:
			case 39:
			case 40:
			case 41:
			case 43:
					document.getElementById('divOrdersLbl').style.display='none';
					document.getElementById('divReqLbl').style.display='none';
					document.getElementById('divLinkToContact').style.display='';
					obj.options[0]=new Option("Linked to Contact Billing Address", "2", false, true);
					obj.options[1]=new Option("Linked to Contact Home Address", "3", false, false);
					obj.options[2]=new Option("Linked to Contact Office Address", "4", false, false);
					obj.options[3]=new Option("Linked to Contact Shipping Address", "5", false, false);
					obj.options[4]=new Option("Not Linked to Contact", "6", false, false);
					break;
			case 42:
					document.getElementById('divOrdersLbl').style.display='none';
					document.getElementById('divReqLbl').style.display='none';
					document.getElementById('divLinkToContact').style.display='';
					obj.options[0]=new Option("Not Linked to Contact", "6", false, true);
					break;
			case 7:
			case 45:
			case 44:
			case 8:
			case 47:
			case 48:
			case 49:
					document.getElementById('divOrdersLbl').style.display='none';
					document.getElementById('divReqLbl').style.display='none';
					document.getElementById('divLinkToContact').style.display='';
					obj.options[0]=new Option("Linked to Contact", "1", false, true);
					break;
			case 10:
			case 28:
			case 11:
			case 12:
			case 19:
			case 20:
			case 21:
			case 17:
			case 18:
			case 22:
			case 27:
			case 24:
			case 25:
			case 26:
				document.getElementById('divLinkToContact').style.display='none';
				document.getElementById('divReqLbl').style.display='none';
				document.getElementById('divOrdersLbl').style.display='';
				break;
			case 23:
				document.getElementById('divLinkToContact').style.display='none';
				document.getElementById('divOrdersLbl').style.display='none';
				document.getElementById('divReqLbl').style.display='';
				break;
		}
	}
}

//11/26/2010 choro: new version of this function.This one works in FF
function valRequiredExtended(frm){ //Required check
	var sRtn='';
	var sErrMsg='';
	var aQuestions = new Array();

	//aQuestions=document.frmManage.elements;
	aQuestions=eval('document.' + frm + '.elements');

	for(var i = 0; i<aQuestions.length; i++){
		if(aQuestions[i].id=='QuestionNumber'){
		var qVal=aQuestions[i].value;
		var qName=aQuestions[i].name;
		var qTitle=aQuestions[i].className;
		var row = aQuestions[i].getAttribute('row');
		var qType = aQuestions[i].getAttribute('qtype');

		var req= qVal.substring(qVal.indexOf(",")+1);
		if (req=='True' || req=='1'){ //required answer
			var idx=qName.substring(qName.indexOf("q")+1);
			chName =eval("document."+ frm +".ans"+idx);
			//chName=document.getElementsByName("ans"+idx)[0];
			if (typeof(chName)!='undefined'){
				if (typeof(chName.length)!="undefined")
				{
					var sEmpty='true';
					for (var j=0; j<chName.length; j++ )
					{
						var aVal = chName[j].value;
						var objID	= "ans"+idx+"other"+aVal;
						var otherSpecify = document.getElementById(objID);
						if (chName[j].checked || chName[j].selected)
							{
								if (otherSpecify != null)
									{
										var osVl = otherSpecify.value;
										if (osVl == '' || osVl == null)
											{
												sEmpty='true';
											}
										else
											{
												sEmpty='';
											}
									}
								else
									{
										sEmpty='';
									}
							}
					}
					if (sEmpty!=''){
						//alert ('Please, select an answer for ' + qTitle); sRtn='break';
						sErrMsg = sErrMsg + '\t' + qTitle + '\n';
						if (chName.type!=undefined) chName.focus(); else chName[0].focus();
						//break;
					}
				}
				else if ((qType == 3) || (qType == 10))
				{
					var sEmpty2='true';
					var bSelcted;
					var aVal2 = chName.value;
					var objID2	= "ans"+idx+"other"+aVal2;
					var otherSpecify2 = document.getElementById(objID2);


					if(chName.checked)
					{
						bSelcted = 'true';
					}
					else if(chName.selected)
					{
						bSelcted = 'true';
					}
					else
					{
						bSelcted = 'false';
					}

					if(bSelcted == 'true')
					{
						if (otherSpecify2 != null)
							{
								var osVl2 = otherSpecify2.value;
								if (osVl2 == '' || osVl2 == null)
									{
										sEmpty2='true';
									}
								else
									{
										sEmpty2='';
									}
							}
						else
							{
								sEmpty2='';
							}
					}

					if (sEmpty2!=''){
						//alert ('Please, select an answer for ' + qTitle); sRtn='break';
						sErrMsg = sErrMsg + '\t' + qTitle + '\n';
						chName.focus();
						//break;
					}
				}
				else { //text/Textarea
					if (chName.value==''){
						if (IsAnswerEntryExtended(row,frm)!=''){
							//alert ('Please, enter ' + qTitle);
							sErrMsg = sErrMsg + '\t' + qTitle + '\n';
							chName =eval("document."+ frm +".ans"+idx);
							chName.style.backgroundColor="#FFFF33";
							chName.focus();
							sRtn='break';
							//break;
						}
					}
					else
						{
							chName =eval("document."+ frm +".ans"+idx);
							chName.style.backgroundColor="";
						}
				}
			}
		}
	}
	}

	if(sErrMsg != '')
	{
		alert('Please enter a value for each of the following questions: \n\n' + sErrMsg);
		return 'err';
	}
	else
	{
		return '';
	}
}

//11/26/2010 choro: new version of this function.This one works in FF
function IsAnswerEntryExtended(chkrow,frm)
	{
	var aQst = new Array();
	var aChoice = new Array();
	var ans='';

	//aQst=document.frmManage.elements;
	aQst=eval('document.'+ frm +'.elements');

	for(var i = 0; i<aQst.length; i++){
		if(aQst[i].id=='QuestionNumber'){
			var row = aQst[i].getAttribute('row');
			var qName=aQst[i].name;
			var qtype =aQst[i].getAttribute('qtype');

			var idx=qName.substring(qName.indexOf("q")+1);
			chName =eval("document."+ frm +".ans"+idx); //undefined when no Qtype/choices are defined

			if (chkrow==row){
				if (qtype == 3)	{
					for (var j=0; j<chName.length; j++ ){
					if (chName[j].checked || chName[j].selected){ans='exit';}
					}
				}
				else if(qtype != 6) {
					if (chName.value!='' || chName.value!=null) {
						if (chName.value!=0 || chName.value!=null) {
							ans='exist';
						}
					}
				}
			}
		}
	}
	return  ans;
}
