<?php 

// Check to ensure this file is included in Freeway!
defined('_FEXEC') or die();
?>
<table border="0" width="100%" cellspacing="0" cellpadding="<?php echo CELLPADDING_SUB; ?>">
<?php if (MAIN_TABLE_BORDER == 'yes'){
table_image_border_top(false, false, SURVEY_HEADING_TITLE);
} 
?>
<script language="JavaScript1.3" type="text/javascript">
<!--
function validateForm(theForm) { //form validator
	var cnt,jcnt,value="",err_result="",con_value,con_length;
	if (theForm.question_id[0]){
		for(cnt=0;cnt<theForm.question_id.length;cnt++){
			value="";
			con_value="";
			if (theForm.question_required[cnt].value==1){
				switch(theForm.question_type[cnt].value){
					case '1':  // radio,check
					case '3':
						con_value=eval("theForm.choices_" + theForm.question_id[cnt].value+"[0]");
						if (con_value){
							con_length=eval("theForm.choices_" + theForm.question_id[cnt].value+".length");
							for(jcnt=0;jcnt<con_length;jcnt++){
								if (eval("theForm.choices_" + theForm.question_id[cnt].value+"["+jcnt+"].checked")==true) value="1";
							}
							if (value!="1")
								err_result+="<?php echo ERR_VALUE_REQUIRED; ?>"+(cnt+1)+"\n";
						} else {
							if (eval("theForm.choices_" + theForm.question_id[cnt].value+".checked")==false)
								err_result+="<?php echo ERR_VALUE_REQUIRED; ?>"+(cnt+1)+"\n";
						}
						break;
					case '2':  // pulldown
					case '4':
					case '5':
						value=eval("theForm.choices_" + theForm.question_id[cnt].value + ".value");
						if (value=='' || value=='0'){
							err_result+="<?php echo ERR_VALUE_REQUIRED; ?>"+(cnt+1)+"\n";
						}
				}
			}
		}
	} else {
		if (theForm.question_required.value==1){
			switch(theForm.question_type.value){
				case '1':  // radio,check
				case '3':
					con_value=eval("theForm.choices_" + theForm.question_id.value+"[0]");
					if (con_value){
						con_length=eval("theForm.choices_" + theForm.question_id.value+".length");
						for(jcnt=0;jcnt<con_length;jcnt++){
							if (eval("theForm.choices_" + theForm.question_id.value+"["+jcnt+"].checked")==true) value="1";
						}
						if (value!="1")
							err_result+="<?php echo ERR_VALUE_REQUIRED; ?>1\n";
						} else {
							if (eval("theForm.choices_" + theForm.question_id.value+".checked")==false)
							err_result+="<?php echo ERR_VALUE_REQUIRED; ?>1\n";
						}
						break;
				case '2':  // pulldown
				case '4':  // Single Line
				case '5':  // multiple lines
					value=eval("theForm.choices_" + theForm.question_id.value + ".value");
					if (value=='' || value=='0'){
						err_result+="<?php echo ERR_VALUE_REQUIRED; ?>1\n";
					}
			}
		}
	}
	if (err_result!=''){
		alert(err_result);
		return false;
	}
	return (true);
}
-->
</script>
    <tr>
    	<td width=100% align=left valign="top">
		<table border="0" width="100%" cellspacing="0" cellpadding="0">
		<?php if ($sur_cnt>0){ ?>
			<tr>
				<td class="main"><b><?php echo TEXT_SURVEY_NAME . $survey_result['survey_name']; ?></b></td>  
			</tr>
			<tr>
				<td><?php echo tep_draw_separator('pixel_trans.gif','1','5'); ?></td>
			</tr>
			<tr>
				<td class="main"><?php echo $survey_result['survey_desc']; ?></td>  
			</tr>
			<tr>
				<td><?php echo tep_draw_separator('pixel_trans.gif','1','10'); ?></td>
			</tr>
		<?php }
			if ($survey_accept!='accept') { 
		?>
	    	<tr>
				<td>
				<table border="0" cellspacing="2" cellpadding="2" class=formArea width=100%>
				<?php if ($survey_accept=='date_expires') { ?>
		        	<tr>
				   		<td class="main"><?php echo sprintf(TEXT_SURVEY_TIME_INTRO,$survey_result['survey_time_period']); ?>.</td>
					</tr>
					<tr>
				   		<td class="main"><?php echo TEXT_SURVEY_FILL_DATE . format_date($flag_result['survey_flag_date']);?>.</td>
					</tr>
					<tr>
						<td class="main"><?php echo TEXT_SURVEY_FUTURE_DATE . format_date($flag_result['check_date']); ?>.</td>
					</tr>
				<?php } else if ($survey_accept=='empty_question') { ?>
					<tr>
						<td class="main"><?php echo TEXT_EMPTY_QUESTION; ?></td>
					</tr>
				<?php } else { ?>
					<tr>
						<td class="main"><?php echo TEXT_EMPTY_SURVEY;?></td>
					</tr>
				<?php } ?>
				</table>
				</td>
			</tr>
		<?php } else { 
				echo tep_draw_form('submit_survey',tep_href_link(FILENAME_SERVICES_SURVEYS_PROCESS,'','SSL'),'post','onSubmit=" return validateForm(this)"');
		?>
			<tr>
				<td>
				<table border="0" cellspacing="0" cellpadding="2" class="formArea" width=100%>
					<tr>
					<input type="hidden" name="survey_id" value="<?php echo $survey_result['survey_id']; ?>">
					<input type="hidden" name="login_id" value="<?php echo $cuID; ?>">
	    			<td valign="top">
					<table border="0" cellspacing="0" cellpadding="4">
					<?php 
						while($question_result = tep_db_fetch_array($question_query)){ 
							$choice_query=tep_db_query("SELECT choice_id,choice_text from " . TABLE_SERVICES_SURVEYS_CHOICE . " where question_id='" . $question_result['question_id'] . "' order by choice_id");
							if ($question_result['question_type']>3 || tep_db_num_rows($choice_query)>0){
					?>
					<tr>
						<td class="main" align=right><?php if ($question_result['question_type']!=6) echo $counter . ". ";?></td>
						<td class="main" align=left>
							<?php echo $question_result['question_text'];
									echo '&nbsp;<i>' . ($question_result['question_required']==1?'(' .TEXT_REQUIRED . ')':'') . '</i>' 
							?>
						</td>
					</tr>
					<?php 
					
					$choice = "";
					$choice_array=array();
					$choice_array[]=array('id'=>0,text=>'');
					while($choice_result = mysql_fetch_array ($choice_query)){
						switch ($question_result["question_type"]){
							case 1: //radio
								$choice .= "&nbsp;&nbsp;" . tep_draw_radio_field("choices_" . $question_result['question_id'] . "[]",$choice_result['choice_id'],false,'id="choices_' . $question_result['question_id'] . '"') . "&nbsp;" . $choice_result["choice_text"] . "<br>";
								break;
							case 2: //pulldown
								$choice_array[]=array('id'=>$choice_result['choice_id'],'text'=>$choice_result['choice_text']);
								break;
							case 3: //checkbox
								$choice .= "&nbsp;&nbsp;" . tep_draw_checkbox_field("choices_" . $question_result['question_id'] . "[]",$choice_result['choice_id'],false,'id="choices_' . $question_result['question_id'] . '"') . "&nbsp;" . $choice_result["choice_text"] . "<br>";
								break;
						}
					}
					?>
					<tr>
						<td class="main"></td>
						<td class="main" align=left>
						<?php 
							switch ($question_result["question_type"]){
								case 2:
									$choice=tep_draw_pull_down_menu("choices_" . $question_result['question_id'] . "[]",$choice_array,'','id="choices_' . $question_result['question_id'] . '"');
									break;
								case 4:
									$choice="&nbsp;&nbsp;" . tep_draw_input_field("choices_" . $question_result['question_id'] . "[]",'','size=90 id="choices_' . $question_result['question_id'] . '"');
									break;
								case 5:
									$choice="&nbsp;&nbsp;<table width=100% border='0'><tr><td>" . tep_draw_textarea_field("choices_" . $question_result['question_id'] . "[]" ,false,10,3,'','id="choices_' . $question_result['question_id'] . '"') . "</td></tr></table>";
									break;
							}
							echo $choice;
						?>
						</td>
					</tr>
					<tr>
						<td><?php echo tep_draw_separator('pixel_trans.gif','1','10'); ?></td>
					</tr>
					<?php 
							if ($question_result['question_type']!=6) {
								$counter++;
								echo tep_draw_hidden_field('question_required[]',$question_result['question_required'],'id="question_required"');
								echo tep_draw_hidden_field('question_type[]',$question_result['question_type'],'id="question_type"');
								echo tep_draw_hidden_field('question_id[]',$question_result['question_id'],'id="question_id"');
							}
						}
						} if ($counter==1){
					?>
					<tr>
						<td class="main"><?php echo TEXT_EMPTY_QUESTION; ?></td>
					</tr>
				<?php } ?>
				</table>
				</td>
			</tr>
		</table>
		</td>
		</tr>
		<tr>
			<td><?php echo tep_draw_separator('pixel_trans.gif','1','10'); ?></td>
		</tr>
		<tr>
			<td>
				<?php if ($counter>1) echo tep_template_image_submit('button_submit_survey.gif',IMAGE_SURVEY_SUBMIT); ?>
			</td>
	    </tr>
	  
		</form>
	   <?php } ?>
		<tr>
			<td><?php echo tep_draw_separator('pixel_trans.gif','1','10'); ?></td>
		</tr>
		<tr>
			<td class="smalltext" align="center"><?php echo SURVEY_FOOTER;?></td>
		</tr>
		<!-- body_eof //-->
	</table>
	</td>
</tr>
<?php 
if (MAIN_TABLE_BORDER == 'yes'){
	table_image_border_bottom();
} ?>       
</table>
