<script language="javascript">
    var asInitVals = new Array();

    $(document).ready(function() {
        $("#tabs").tabs( {
            "show": function(event, ui) {
                var oTable = $('div.dataTables_scrollBody>table.display', ui.panel).dataTable();
                var tab1 = $("#tabs-1").is(":visible");
                var tab2 = $("#tabs-2").is(":visible");
                var tab3 = $("#tabs-3").is(":visible");

                if(tab1)
                {
                    $("#tab_id").val("1");
                }
                if(tab2)
                {
                    $("#tab_id").val("2");
                }
                if(tab3)
                {
                    $("#tab_id").val("3");
                }

                if ( oTable.length > 0 ) {
                    oTable.fnAdjustColumnSizing();
                }
            }
        } );
		
		$('#q1, #q2, #q3, #q6, #q8, #q11').change(function(){
			default_val();
		});
    } );
	
	function default_val()
	{
		if(($('#q1').val() == 0) && ($('#q2').val() == 1) && ($('#q3').val() >= 18) && ($('#q6').val() == 1) && ($('#q8').val() == "M"))
			$("#q11").val(1);
		else
			$("#q11").val(0);
	}
    function part_id()
    {
        if(navigator.appName != "Microsoft Internet Explorer")
            frmname = document.recuirtment;

        lcn = frmname.location.value;
        lcn_typ = frmname.location_type.value;
        frmname.participant_id.value = lcn+lcn_typ;
    }
	
	jQuery(function(e1){
		jQuery("#q1").validate({
			expression: "if (VAL) return true; else return false;",
			message: "Please Answer for Q1"
		});
		jQuery("#q1a").validate({
			expression: "if ((jQuery('#q1').val() == 0) || VAL) return true; else return false;",
			message: "Please Answer for Q1a"
		});
		jQuery("#q1a").validate({
			expression: "if ((jQuery('#q1').val() == 0) || VAL.match(/^[A-Z]{2}[0-9]{4}$/)) return true; else return false;",
			message: "Please Provide Valid Value in Q1a"
		});
		jQuery("#q2").validate({
			expression: "if ((jQuery('#q1').val() == 1) || VAL) return true; else return false;",
			message: "Please Answer for Q2"
		});
		jQuery("#q3").validate({
			expression: "if ((jQuery('#q1').val() == 1) || VAL) return true; else return false;",
			message: "Please Answer for Q3"
		});
		jQuery("#q4").validate({
			expression: "if ((jQuery('#q1').val() == 1) || VAL) return true; else return false;",
			message: "Please Answer for Q4"
		});
		jQuery("#q4").validate({
			expression: "if ((jQuery('#q1').val() == 0 && eval(VAL) <= jQuery('#q3').val()) || jQuery('#q1').val() == 1) return true; else return false;",
			message: "Answer for Q4 Cannot be greater than age (Q3)"
		});
		jQuery("#q5").validate({
			expression: "if ((jQuery('#q1').val() == 1) || VAL) return true; else return false;",
			message: "Please Answer for Q5"
		});
		jQuery("#q6").validate({
			expression: "if ((jQuery('#q1').val() == 1) || VAL) return true; else return false;",
			message: "Please Answer for Q6"
		});
		jQuery("#q7").validate({
			expression: "if ((jQuery('#q1').val() == 1) || VAL) return true; else return false;",
			message: "Please Answer for Q7"
		});
		jQuery("#q8").validate({
			expression: "if ((jQuery('#q1').val() == 1) || VAL) return true; else return false;",
			message: "Please Answer for Q8"
		});
		jQuery("#q9").validate({
			expression: "if ((jQuery('#q1').val() == 1) || VAL || jQuery('#q8').val() == 'F' || jQuery('#q8').val() == 'H') return true; else return false;",
			message: "Please Answer for Q9"
		});
		jQuery("#q10").validate({
			expression: "if ((jQuery('#q1').val() == 1) || VAL) return true; else return false;",
			message: "Please Answer for Q10"
		});
	});
	
    function frm_validation()
    {
        if(navigator.appName != "Microsoft Internet Explorer")
            frmname = document.recuirtment;

        var tab1 = $("#tabs-1").is(":visible");
        var tab2 = $("#tabs-2").is(":visible");
        var tab3 = $("#tabs-3").is(":visible");

        if(tab1)
            $("#tab_id").val("1");
        if(tab2)
            $("#tab_id").val("2");
        if(tab3)
            $("#tab_id").val("3");
	}
	
	function frm_edit_val(frmval)
	{
		if(frmval != "")
		{
			var url = "";
			var loc = window.location;
			var pathName = loc.pathname.substring(0, loc.pathname.lastIndexOf('/') + 1);
			url = loc.href.substring(0, loc.href.length - ((loc.pathname + loc.search + loc.hash).length - pathName.length));
			
			if(frmval != "")
			{
				$.ajax({
					type: "POST",
					data: "page="+getUrlVars()["page"]+"&mode=edit&id="+frmval,
					url: url+"index.php?page="+getUrlVars()["page"],
					error: function(msg){
						alert( msg.status );
					},
					success: function(msg){
						// alert(msg);
						close_frame();
						$('#tabs-1').html(msg);
						$("#delete_img").show();
					}
				});
			}
		}
	}
	
	function skip_q9(val)
	{
		if(val == "F" || val == "H")
		{
			$("#disp_q9").hide();
		}
		else
		{
			$("#disp_q9").show();
		}
	}
	
	function enb_q1(val)
	{
		if(val == 1)
		{
			$("#disp_q1a").show();
			$("#disp_q2").hide();
			$("#disp_q3").hide();
			$("#disp_q4").hide();
			$("#disp_q5").hide();
			$("#disp_q6").hide();
			$("#disp_q7").hide();
			$("#disp_q8").hide();
			$("#disp_q9").hide();
			$("#disp_q10").hide();
		}
		else
		{
			$("#disp_q1a").hide();
			$("#disp_q2").show();
			$("#disp_q3").show();
			$("#disp_q4").show();
			$("#disp_q5").show();
			$("#disp_q6").show();
			$("#disp_q7").show();
			$("#disp_q8").show();
			$("#disp_q9").show();
			$("#disp_q10").show();
		}
	}
</script>
<style>
div.ValidationErrors {
    color: #DD0000;
    font-size: 12px;
    font-style: italic;
    padding-top: 10px;
    font-weight: bold;
}
.form {
	width: 100%;
}
.question {
	width: 60%;
}
.answer {
	width: 40%;
}
</style>
<?php
	$yes_no = array(0 => "No", 1 => "Yes");
	$yes_no_dk = array(0 => "No", 1 => "Yes", 997 => "Don't Know", 998 => "Refused");
	$q9 = array(1 => "Panthi", 2 => "Kothi", 3 => "Double-decker", 4 => "Gay", 5 => "Bisexual", 6 => "MSM", 7 => "Other");
?>
<div style="width: 95%; margin: 0 auto; padding: 10px;" id="content">
    <div id="frm_display">
        <div id="tabs">
            <ul>
                <li class="active"><a href="#tabs-1">&nbsp;Screening Form&nbsp;</a></li>
            </ul>
            <form class="form" name="recuirtment" id="recuirtment" method="post" action="<?php echo $action; ?>" onsubmit="return frm_validation();">
                <div id="tabs-1">
					<div id="disp_q0" style="display: none;">
						<div class="questionrow">
							<div class="question">Participant ID</div>
							<div class="answer">
								<input type="hidden" name="loc_id" id="loc_id" value="<?php echo $loc_id; ?>" readonly />
								<input type="hidden" name="partcpnt_id" id="partcpnt_id" value="<?php echo $part_id; ?>" readonly />
								<!--<img src="includes/images/search_img.png" style="vertical-align: middle;" onclick="open_frame('autocomplete.php');">-->
							</div>
						</div>
						<div class="clear_form">
						</div>
					</div>
					<div id="disp_q1">
						<div class="questionrow">
							<div class="question">1. Is the participant a duplicate enrollment based on fingerprint?</div>
							<div class="answer">
								<input type="hidden" name="id" id="id" value="<?php echo $id; ?>" />
								<input type="hidden" name="sur_id" id="sur_id" value="<?php echo $sur_id; ?>" />
								<input type="hidden" name="tab_id" id="tab_id" value="" />
								<?php echo $common->generateSelect('q1', $yes_no, $q1, 'onchange="return enb_q1(this.value);"'); ?>
							</div>
						</div>
						<div class="clear_form">
						</div>
					</div>
					<div id="disp_q1a" style="display: none;">
						<div class="questionrow">
							<div class="question">1a. Participant Study ID</div>
							<div class="answer">
								<input type="text" name="q1a" id="q1a" value="<?php echo $q1a; ?>" style="text-transform: uppercase;" maxlength="6" size="7" />
							</div>
						</div>
						<div class="clear_form">
						</div>
                    </div>
					<div id="disp_q2">
						<div class="questionrow">
							<div class="question">2. Does the participant have a valid RDS coupon?</div>
							<div class="answer">
								<?php echo $common->generateSelect('q2', $yes_no, $q2); ?>
							</div>
						</div>
						<div class="clear_form">
						</div>
                    </div>
					<div id="disp_q3">
						<div class="questionrow">
							<div class="question">3. What is your age in years?</div>
							<div class="answer">
								<input type="text" name="q3" id="q3" value="<?php echo $q3; ?>" maxlength="3" onkeyup="return acceptDigits(this);" size="5" /> Years
							</div>
						</div>
						<div class="clear_form">
						</div>
                    </div>
					<div id="disp_q4">
						<div class="questionrow">
							<div class="question">
								4. How long have you lived where you are living now?
								<div style="padding: 5px 0px; font-size: 90%;"><strong>Interviewer Instruction:</strong> Code 00 if less than 1 year.</div>
							</div>
							<div class="answer">
								<input type="text" name="q4" id="q4" value="<?php echo $q4; ?>" maxlength="3" onkeyup="return acceptDigits(this);" size="5" /> Years
							</div>
						</div>
						<div class="clear_form">
						</div>
                    </div>
					<div id="disp_q5">
						<div class="questionrow">
							<div class="question">5. Do you have any plans to move from here in the next two years?</div>
							<div class="answer">
								<?php echo $common->generateSelect('q5', $yes_no_dk, $q5); ?>
							</div>
						</div>
						<div class="clear_form">
						</div>
                    </div>
					<div id="disp_q6">
						<div class="questionrow">
							<div class="question">6. In the past 12 months, have you had oral or anal sex with another man?</div>
							<div class="answer">
								<?php echo $common->generateSelect('q6', $yes_no, $q6); ?>
							</div>
						</div>
						<div class="clear_form">
						</div>
                    </div>
					<div id="disp_q7">
						<div class="questionrow">
							<div class="question">7. Have you ever been tested for HIV?</div>
							<div class="answer">
								<?php echo $common->generateSelect('q7', $yes_no_dk, $q7); ?>
							</div>
						</div>
						<div class="clear_form">
						</div>
                    </div>
					<div id="disp_q8">
						<div class="questionrow">
							<div class="question">8. What is your biological sex?</div>
							<div class="answer">
								<?php $common->dropdown('gen_code', 'gen_name', 'custom_gender_master', '', 'gen_id', 'q8', $q8, 'onchange="return skip_q9(this.value);"'); ?>
							</div>
						</div>
						<div class="clear_form">
						</div>
                    </div>
					<div id="disp_q9">
						<div class="questionrow">
							<div class="question">9. How do you self-identify?</div>
							<div class="answer">
								<?php echo $common->generateSelect('q9', $q9, $q9_ans); ?>
								<script>
									skip_q9("<?php echo $q8; ?>");
								</script>
							</div>
						</div>
						<div class="clear_form">
						</div>
                    </div>
					<div id="disp_q10">
						<div class="questionrow">
							<div class="question">10. Are you currently employed?</div>
							<div class="answer">
								<?php echo $common->generateSelect('q10', $yes_no_dk, $q10); ?>
							</div>
						</div>
						<div class="clear_form">
						</div>
                    </div>
					<div id="disp_q11">
						<div class="questionrow">
							<div class="question">Participant Eligibility</div>
							<div class="answer">
								<?php echo $common->generateSelect('q11', $yes_no, $q11, "style='background: #cfcfcf;'"); ?>
							</div>
						</div>
						<div class="clear_form">
						</div>
                    </div>
                    <div class="questionrow">
                        <div style="padding: 5px;" align="center">
                            <input type="submit" name="Submit" value="Submit" />
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<?php
	if($q1 != "")
	{
		?>
		<script>
			default_val();
		</script>
		<?php
	}
?>