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

    $(document).ready(function() {
		$("#location_sel").change(function() {
			$("#location").val($(this).val());
		});
		
        $("#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();
                }
            }
        } );
    } );
    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(){
		jQuery("#interview_initial").validate({
			expression: "if (VAL) return true; else return false;",
			message: "Please Provide Interviewer Initial"
		});
		jQuery("#location").validate({
			expression: "if (VAL) return true; else return false;",
			message: "Please Provide Location"
		});
		jQuery("#participant_type").validate({
			expression: "if (VAL) return true; else return false;",
			message: "Please Provide Participant Type"
		});
        jQuery("#participant_id").validate({
            expression: "if (VAL) return true; else return false;",
            message: "Please Provide Participant ID"
        });
        jQuery("#participant_id").validate({
            expression: "if (VAL.match(/^[A-Za-z]{3}[0-9]{3}$/)) return true; else return false;",
            message: "Please Provide Valid Participant ID"
        });
		jQuery("#coupon_id").validate({
			expression: "if (VAL) return true; else return false;",
			message: "Please Provide Coupon ID"
		});
	   /*
			jQuery("#recruitment_loc").validate({
				expression: "if (VAL) return true; else return false;",
				message: "Please Provide Recruitment Location"
			});
	   */
    });
	
    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");
		
		if(tab1)
		{
			pattern = /^[A-Za-z]{3}[0-9]{3}$/;
			part_id = $("#participant_id").val();
			
			if($("#interview_initial").val() != "" && $("#location").val() != "" && $("#participant_type").val() != "" && pattern.test(part_id))
			{
				loc = $("#participant_id").val().substr(0, 3);
				if($("#location").val() != loc)
				{
					alert("Please Provide Valid Participant ID" .$("#location").val());
					$("#participant_id").focus();
					return false;
				}
			}
			// Start - Added by Vidhya - 20-10-2017
			/*
			if($("#coupon_id").val != '')
			{
				if($("#coupon_id").val().substr(0, 2).toUpperCase() != 'XX')
				{
					alert("Please enter Valid Coupon ID - It has to start with XX");
					$("#coupon_id").focus();
					return false;
				}
			}
			*/
			// End - Added by Vidhya - 20-10-2017
		}
	}
	
	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 get_survey_location(sur_val, name, default_val)
	{
		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));
		
		$.ajax({
			type: "POST",
			data: "surveyid="+sur_val+"&name="+name+"&location="+default_val,
			url: url+"getsurveylocation.php",
			error: function(msg){
				//alert(msg.status);
			},
			success: function(msg){
				//alert(msg);
				$("#loc_row").html(msg);
				if(name == "location_sel")
				{
					if($("#"+name+" option").length != 1)
						get_location(sur_val, 'location_coupon', true);
				}
			}
		});
	}
</script>
<style>
div.ValidationErrors {
    color: #DD0000;
    font-size: 12px;
    font-style: italic;
    padding-top: 10px;
    font-weight: bold;
}
</style>
<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;Introduction&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 class="questionrow">
                        <div class="question">Survey</div>
                        <div class="answer">
                            <input type="hidden" name="dt_fmt" id="dt_fmt" value="<?php echo DT_FMT; ?>" />
                            <?php
								if($survey_id == "")
									$survey_id = SURVY;
								
								if(SURVYFXD == 'Y')
								{
									echo '<input type="hidden" name="survey_id" id="survey_id" value="'.SURVY.'" />';
									echo SURVYTITLE;
									echo '<script>get_location("'.SURVY.'", \'location_coupon\', true);</script>';
								}
								else
								{
									$common->dropdown('sur_code', 'sur_title', 'custom_survey_master', 'status = "Y"', 'sur_title', 'survey_id', $survey_id, 'class="required" onchange="return get_survey_location(this.value, \'location_sel\', \'\');"');
								}
                            ?>
                        </div>
                    </div>
                    <div class="clear_form">
                    </div>
                    <div class="questionrow">
                        <div class="question">Date of Interview</div>
                        <div class="answer">
                            <?php
                            $dt_fmt = str_replace("mm", "m", DT_FMT);
                            $dt_fmt = str_replace("dd", "d", $dt_fmt);
                            $dt_fmt = str_replace("yyyy", "Y", $dt_fmt);
                            date_default_timezone_set('Asia/Calcutta');
                            echo '<span id="dor_span">' . date($dt_fmt) . '</span>';
                            ?>
                            <input type="hidden" name="id" id="id" value="" />
                            <input type="hidden" name="tab_id" id="tab_id" value="" />
                            <input type="hidden" name="doi" id="doi" value="<?php echo date($dt_fmt); ?>" />
                        </div>
                    </div>
                    <div class="clear_form">
                    </div>
                    <div class="questionrow">
                        <div class="question">Interview’s Initial's</div>
                        <div class="answer">
                            <input type="text" name="interview_initial" id="interview_initial" value="<?php echo $interview_initial; ?>" maxlength="3" onkeyup="return acceptDigits(this);" style="text-transform: uppercase;" size="7" />
                        </div>
                    </div>
                    <div class="clear_form">
                    </div>
                    <div class="questionrow">
                        <div class="question">Which Location do you belong to?</div>
                        <div class="answer">
                            <input type="hidden" name="location" id="location" value="" />
                            <input type="hidden" name="location_fxd" id="location_fxd" value="" />
							<span id="loc_row">
							<?php 
								$common->dropdown('loc_code', 'loc_name', 'custom_location', '', 'loc_name', 'location_sel', $location, '');
								echo '<script>get_survey_location("'.SURVY.'", \'location_sel\', \'\');</script>';
							?>
							</span>
                        </div>
                    </div>
                    <div class="clear_form">
                    </div>
                    <div class="questionrow">
                        <div class="question">Participant Type</div>
                        <div class="answer">
                            <select name="participant_type" id="participant_type">
                                <option value="">Select</option>
                                <option value="S">Seed</option>
                                <option value="W">Recruit</option>
                            </select>
                        </div>
                    </div>
                    <div class="clear_form">
                    </div>
                    <?php if(COUPONFXD == 'Y'): ?>
                        <div class="questionrow">
                            <div class="question">Participant ID</div>
                            <div class="answer">
                                <input type="text" name="participant_id" id="participant_id" value="<?php echo $participant_id; ?>" maxlength="6" />
                            </div>
                        </div>
                        <div class="clear_form">
                        </div>
                    <?php else: ?>
                        <div class="questionrow">
                            <div class="question">Coupon ID</div>
                            <div class="answer">
                                <input type="text" name="coupon_id" id="coupon_id" value="<?php echo $participant_id; ?>" maxlength="6" />
                            </div>
                        </div>
                        <div class="clear_form">
                        </div>
                    <?php endif; ?>	
                   <div style="display: none;">					
                    <div class="questionrow">
                        <div class="question">Recruitment Location</div>
                        <div class="answer">
                            <select name="recruitment_loc" id="recruitment_loc">
                                <option value="">Select</option>
                                <option value=1>Transport (A'Mandi)</option>
                                <option value=2>Gorakhnath-10</option>
                            </select>
                        </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>