<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");

                if(tab1)
                    $("#tab_id").val("1");

                if ( oTable.length > 0 ) {
                    oTable.fnAdjustColumnSizing();
                }
            }
        } );
    } );
	
    function frm_validation()
    {
        if(navigator.appName != "Microsoft Internet Explorer")
            catgry = document.survey;

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

        if(tab1)
            $("#tab_id").val("1");

        if(tab1)
        {
			var Coupons = $("#cupn_chk").is(":checked");
			var Incentive = $("#incentive_chk").is(":checked");
			
            if(catgry.survey_id.value == "")
            {
                alert("Please Provide Survey");
                catgry.survey_id.focus();
                return false;
            }
            if(catgry.fy.value == "")
            {
                alert("Please Provide Financial Year");
                catgry.fy.focus();
                return false;
            }
            /*if(catgry.reimbsmnt_vchr.value == "")
            {
                alert("Please Provide Reimbursement Voucher Prefix");
                catgry.reimbsmnt_vchr.focus();
                return false;
            }*/
            if(catgry.location.value == "")
            {
                alert("Please Provide Location");
                catgry.location.focus();
                return false;
            }
			if(Coupons)
			{
				if(catgry.no_of_coupon.value == "")
				{
					alert("Please Provide No of coupons per participant");
					catgry.no_of_coupon.focus();
					return false;
				}
				if(catgry.cupn_prd.value == "")
				{
					alert("Please Provide Coupon Validity Period");
					catgry.cupn_prd.focus();
					return false;
				}
				if(catgry.prd_type.value == "")
				{
					alert("Please Provide Coupon Validity Period Type");
					catgry.prd_type.focus();
					return false;
				}
			}
			if(Incentive)
			{
				if(catgry.incentive_amt.value == "")
				{
					alert("Please Provide Incentive Amount");
					catgry.incentive_amt.focus();
					return false;
				}
				/*if(catgry.incentive_vchr.value == "")
				{
					alert("Please Select Incentive Voucher Prefix");
					catgry.incentive_vchr.focus();
					return false;
				}*/
			}
        }
    }
	
	function frm_edit_val(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));
		
		$.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){
					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("&nbsp;"+msg);
			}
		});
	}
	
	function enc_cupn(chk_val)
	{
		if(!chk_val)
		{
			$("#cupn_cde_chk_row").hide();
			$("#no_of_coupon_row").hide();
			$("#cupn_prd_row").hide();
		}
		else
		{
			$("#cupn_cde_chk_row").show();
			$("#no_of_coupon_row").show();
			$("#cupn_prd_row").show();
		}
	}
	
	function enc_incentive(chk_val)
	{
		if(!chk_val)
		{
			$("#incentive_amt_row").hide();
			// $("#incentive_vchr_row").hide();
		}
		else
		{
			$("#incentive_amt_row").show();
			// $("#incentive_vchr_row").show();
		}
	}
</script>
<style>
	#dataTable {
		line-height: 15px !important
	}
</style>
<?php
	$qry = "SELECT * FROM ".$table_name;
	$common->sql->query($qry, SQL_ALL, SQL_ASSOC);
	$rec = $common->sql->record[0];
	$id = $rec[$primary_key];
	$tz = $rec['stngs_timezone'];
	$fy = $rec['stngs_financial_year'];
	$dt_fmt = $rec['stngs_dateformat'];
	$incen_amt = $rec['stngs_incendv_amt'];
	$location = $rec['stngs_location'];
	
	$org_name = $rec['stngs_org_name'];
	$org_addrs = $rec['stngs_org_addrs'];
	$org_phone = $rec['stngs_org_phone'];
	$org_mail = $rec['stngs_org_mail'];
	$org_website = $rec['stngs_org_website'];
	
	$frm_name = $rec['smtp_admin_name'];
	$frm_mail = $rec['smtp_frm_mail'];
	$smtp_server = $rec['smtp_server_name'];
	$smtp_port = $rec['smtp_server_port'];
	$usr_name = $rec['smtp_server_usrname'];
	$usr_pwd = $rec['smtp_server_pwd'];
	$smtp_ssl = $rec['smtp_server_ssl'];
	$smtp_auth = $rec['smtp_server_auth'];
	
	if($smtp_ssl == 1)
		$smtp_sll = "checked";
	if($smtp_auth == 1)
		$smtp_auth = "checked";
?>
<div style="width: 95%; margin: 0 auto; padding: 10px;">
	<div id="frm_display">
        <div id="tabs">
            <ul>
                <li class="active"><a href="#tabs-1">&nbsp;Application Settings&nbsp;</a></li>
            </ul>
            
            <form class="form" name="survey" id="survey" 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">
                            <?php
								if($survey_id == "")
									$survey_id = SURVY;
								
								if(SURVYFXD == 'Y')
								{
									echo '<input type="hidden" name="survey_id" id="survey_id" value="'.SURVY.'" />';
									echo SURVYTITLE;
								}
								else
								{
									$common->dropdown('sur_code', 'sur_title', 'custom_survey_master', 'sur_code NOT IN (SELECT app_survey_id FROM custom_app_settings)', 'sur_title', 'survey_id', $survey_id, 'class="required" onchange="return get_survey_location(this.value, \'location\', \'\');"');
								}
                            ?>
                        </div>
                    </div>
                    <div class="clear_form">
                    </div>
                    <div class="questionrow">
                        <div class="question">Coupons</div>
                        <div class="answer">
                            <input type="checkbox" name="cupn_chk" id="cupn_chk" value="Y" <?php echo $cupn_chk; ?> onclick="return enc_cupn(this.checked);" />
                        </div>
                    </div>
                    <div class="clear_form">
                    </div>
                    <div class="questionrow">
                        <div class="question">Incentive</div>
                        <div class="answer">
                            <input type="checkbox" name="incentive_chk" id="incentive_chk" value="Y" <?php echo $incentive_chk; ?> onclick="return enc_incentive(this.checked);" />
                        </div>
                    </div>
                    <div class="clear_form">
                    </div>
                    <div class="questionrow">
                        <br/>
                    	<table border="0" cellpadding="0" cellspacing="0" style="width: 100%; line-height: 40px;" id="dataTable" align="center">
                        	<tr>
                            	<td class="question_title" width="50%">&nbsp;</td>
                                <td class="question_title">&nbsp;</td>
                                <td class="question_title" align="center">Fixed</td>
                            </tr>
                            <tr>
                            	<td class="question_title">Financial Year</td>
                                <td class="question">&nbsp;<select name="fy" id="fy" class="required">
										<option value="">Select</option>
										<?php
											$st_fncl_yr = 2010;
											$no_of_fncl_yr = date("Y")+1;
											for($i=$st_fncl_yr; $i<=$no_of_fncl_yr; $i++)
												echo '<option value="'.substr($i, -2).substr(($i+1), -2).'">'.$i.' - '.($i+1).'</option>';
										?>
									</select>
								</td>
                                <td class="question" align="center">
									<input type="checkbox" name="fy_chk" id="fy_chk" value="Y" <?php echo $fy_chk; ?> style="display: none;" />
								</td>
                            </tr>
                            <tr style="display: none;">
                            	<td class="question_title">Reimbursement Voucher Prefix</td>
                                <td class="question">&nbsp;<input type="text" name="reimbsmnt_vchr" id="reimbsmnt_vchr" value="<?php echo $reimbsmnt_vchr; ?>" />
								</td>
                                <td class="question" align="center">
									<input type="checkbox" name="reimbsmnt_vchr_chk" id="reimbsmnt_vchr_chk" value="Y" <?php echo $reimbsmnt_vchr_chk; ?> />
								</td>
                            </tr>
                            <tr>
                            	<td class="question_title">Default Location</td>
                                <td class="question" id="loc_row">&nbsp;<?php $common->dropdown('loc_code', 'loc_name', 'custom_location', '', 'loc_name', 'location', $location, 'class="required"'); ?></td>
                                <td class="question" align="center">
									<input type="checkbox" name="location_chk" id="location_chk" value="Y" <?php echo $location_chk; ?> />
								</td>
                            </tr>
                            <tr id="cupn_cde_chk_row">
                            	<td class="question_title">Coupon code is Participant ID</td>
                                <td class="question">&nbsp;
									<input type="checkbox" name="cupn_cde_chk" id="cupn_cde_chk" value="Y" <?php echo $cupn_cde_chk; ?> />
								</td>
                                <td class="question">&nbsp;</td>
                            </tr>
                            <tr id="no_of_coupon_row">
                            	<td class="question_title">No of coupons per participant</td>
                                <td class="question">&nbsp;<input type="text" name="no_of_coupon" id="no_of_coupon" value="<?php echo $no_of_coupon; ?>" /></td>
                                <td class="question" align="center">
									<input type="checkbox" name="no_of_coupon_chk" id="no_of_coupon_chk" value="Y" <?php echo $no_of_coupon_chk; ?> />
								</td>
                            </tr>
                            <tr id="cupn_prd_row">
                            	<td class="question_title">Coupon Validity Period</td>
                                <td class="question">&nbsp;<input type="text" name="cupn_prd" id="cupn_prd" value="" size="7" />
									<select name="prd_type" id="prd_type">
										<option value="" selected="selected">Select</option>
										<option value="1">Days</option>
										<option value="2">Weeks</option>
										<option value="3">Month</option>
										<option value="4">Year</option>
									</select>
								</td>
                                <td class="question" align="center">
									<input type="checkbox" name="cupn_prd_chk" id="cupn_prd_chk" value="Y" <?php echo $cupn_prd_chk; ?> />
								</td>
                            </tr>
                            <tr id="incentive_amt_row">
                            	<td class="question_title">Incentive Amount</td>
                                <td class="question">&nbsp;<input type="text" name="incentive_amt" id="incentive_amt" value="<?php echo $incen_amt; ?>" style="text-align: right;" />
								</td>
                                <td class="question" align="center">
									<input type="checkbox" name="incentive_amt_chk" id="incentive_amt_chk" value="Y" <?php echo $incentive_amt_chk; ?> />
								</td>
                            </tr>
                            <tr id="incentive_vchr_row" style="display: none;">
                            	<td class="question_title">Incentive Voucher Prefix</td>
                                <td class="question">&nbsp;<input type="text" name="incentive_vchr" id="incentive_vchr" value="<?php echo $incentive_vchr; ?>" />
								</td>
                                <td class="question" align="center">
									<input type="checkbox" name="incentive_vchr_chk" id="incentive_vchr_chk" value="Y" <?php echo $incentive_vchr_chk; ?> />
								</td>
                            </tr>
                            <tr id="bio_ref_chk_row">
                            	<td class="question_title">Bio-Metric Reference Required</td>
                                <td class="question">&nbsp;
									<input type="checkbox" name="bio_ref_chk" id="bio_ref_chk" value="Y" <?php echo $bio_ref_chk; ?> />
								</td>
                                <td class="question">&nbsp;</td>
                            </tr>
                            <tr id="sur_cmp_chk_row">
                            	<td class="question_title">Survey Completion Required</td>
                                <td class="question">&nbsp;
									<input type="checkbox" name="sur_cmp_chk" id="sur_cmp_chk" value="Y" <?php echo $sur_cmp_chk; ?> />
								</td>
                                <td class="question">&nbsp;</td>
                            </tr>
                            <tr id="lab_req_chk_row">
                            	<td class="question_title">Lab Request Required</td>
                                <td class="question">&nbsp;
									<input type="checkbox" name="lab_req_chk" id="lab_req_chk" value="Y" <?php echo $lab_req_chk; ?> />
								</td>
                                <td class="question">&nbsp;</td>
                            </tr>
                            <!-- added by vidhya on 30/11/17 -->
                            <tr id=var_show_chk_row">
        						<td class="question_title">Show Coupon Variables</td>
            					<td class="question">&nbsp;
								<input type="checkbox" name="var_show_chk" id="var_show_chk" value="Y" <?php echo $var_show_chk; ?> />
								</td>
            					<td class="question">&nbsp;</td>
        					</tr>
        					
        					<!-- added by vidhya on 08/12/17 -->
                            <tr id=var_only_std_arm">
        						<td class="question_title">Only Standard Arm</td>
            					<td class="question">&nbsp;
								<input type="checkbox" name="var_std_arm" id="var_std_arm" value="Y" <?php echo $var_std_arm; ?> />
								</td>
            					<td class="question">&nbsp;</td>
        					</tr>
                        </table>
                        <br/>
                    </div>
                    <div class="clear_form">
                    </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
	echo '<script language="javascript">';
	if($fy != "")
		echo 'select_checked("fy", "'.$fy.'", "");';
	echo '$("#cupn_cde_chk_row").hide();';
	echo '$("#no_of_coupon_row").hide();';
	echo '$("#cupn_prd_row").hide();';
	echo '$("#incentive_amt_row").hide();';
	echo '$("#incentive_vchr_row").hide();';
	// echo '$("#bio_ref_chk_row").hide();';
	// echo '$("#sur_cmp_chk_row").hide();';
	// echo '$("#lab_req_chk_row").hide();';
	echo '</script>';
?>