<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();
                }
            }
        } );
		
		$('#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 default_val()
	{
		if(($('#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('#q2').val() == 0) || VAL) return true; else return false;",
			message: "Please Answer for Q1"
		});
		jQuery("#q3").validate({
			expression: "if ((jQuery('#q2').val() == 0) || VAL) return true; else return false;",
			message: "Please Answer for Q2"
		});
		jQuery("#q4").validate({
			expression: "if ((jQuery('#q2').val() == 0) || VAL) return true; else return false;",
			message: "Please Answer for Q3"
		});
		jQuery("#q4").validate({
			expression: "if ((jQuery('#q2').val() == 1 && eval(VAL) <= jQuery('#q3').val()) || jQuery('#q2').val() == 0) return true; else return false;",
			message: "Answer for Q3 Cannot be greater than age (Q2)"
		});
		jQuery("#q5").validate({
			expression: "if ((jQuery('#q2').val() == 0) || VAL) return true; else return false;",
			message: "Please Answer for Q4"
		});
		jQuery("#q6").validate({
			expression: "if ((jQuery('#q2').val() == 0) || VAL) return true; else return false;",
			message: "Please Answer for Q5"
		});
		jQuery("#q7").validate({
			expression: "if ((jQuery('#q2').val() == 0) || VAL) return true; else return false;",
			message: "Please Answer for Q6"
		});
		jQuery("#q8").validate({
			expression: "if ((jQuery('#q2').val() == 0) || VAL) return true; else return false;",
			message: "Please Answer for Q7"
		});
	  /*
		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 == 0)
		{			
			$("#disp_q3").hide();
			$("#disp_q4").hide();
			$("#disp_q5").hide();
			$("#disp_q6").hide();
			$("#disp_q7").hide();
			$("#disp_q8").hide();
			$("#disp_q14").hide();
			$("#disp_q15").hide();
			$("#disp_q16").hide();
			
		}
		else
		{			
			$("#disp_q3").show();
			$("#disp_q4").show();
			$("#disp_q5").show();
			$("#disp_q6").show();
			$("#disp_q7").show();
			$("#disp_q8").show();
			$("#disp_q14").show();
			$("#disp_q15").show();
			$("#disp_q16").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" style="display: none;">
						<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); ?>
							</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">1. Does the participant have a valid RDS coupon?</div>
							<div class="answer">
								<?php echo $common->generateSelect('q2', $yes_no, $q2, 'onchange="return enb_q1(this.value);"'); ?>
							</div>
						</div>
						<div class="clear_form">
						</div>
                    </div>
					<div id="disp_q3">
						<div class="questionrow">
							<div class="question">2. 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">
								3. How long have you lived where you are living now?								
							</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">4. 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">5. 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">6. 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_q14">
						<div class="questionrow">
							<div class="question">6.1 Commonly where do you go for HIV testing?</div>
							<div class="answer">
								<input type="text" name="q14" id="q14" value="<?php echo $q14; ?>" /> 
							</div>
						</div>
						<div class="clear_form">
						</div>
                    </div>
					
					<div id="disp_q15">
						<div class="questionrow">
							<div class="question">6.2 Where do you access Condom/Lubricant?</div>
							<div class="answer">
								<input type="text" name="q15" id="q15" value="<?php echo $q15; ?>" /> 
							</div>
						</div>
						<div class="clear_form">
						</div>
                    </div>
					
					<div id="disp_q16">
						<div class="questionrow">
							<div class="question">6.3 Where do you go for STI/STD testing and treatment?</div>
							<div class="answer">
								<input type="text" name="q16" id="q16" value="<?php echo $q16; ?> "/> 
							</div>
						</div>
						<div class="clear_form">
						</div>
                    </div>
					
					
					<div id="disp_q8">
						<div class="questionrow">
							<div class="question">7. What is your biological sex?</div>
							<div class="answer">
								<?php $common->dropdown('gen_code', 'gen_name', 'custom_gender_master', '', 'gen_id', 'q8', $q8); ?>
							</div>
						</div>
						<div class="clear_form">
						</div>
                    </div>
					<div id="disp_q9" style="display: none;">
						<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" style="display: none;">
						<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
	}
?>