<?php echo '
<link rel="stylesheet" href="includes/media/css/TableTools_JUI.css" type="text/css" />
<script type="text/javascript" language="javascript" src="includes/media/js/ZeroClipboard.js"></script>
<script type="text/javascript" language="javascript" src="includes/media/js/TableTools.js"></script>
'; ?>
<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 tab3 = $("#tabs-3").is(":visible");
				
				if(tab3)
					$("#tab_id").val("3");
				
				if ( oTable.length > 0 ) {
					oTable.fnAdjustColumnSizing();
				}
			}
		} );
	} );
	
    function frm_validation()
    {
        if(navigator.appName != "Microsoft Internet Explorer")
            catgry = document.recuirtment;

        var tab1 = $("#tabs-3").is(":visible");
        if(tab1)
            $("#tab_id").val("1");
		
		prd_frm = $("#prd_frm").val();
		prd_to = $("#prd_to").val();
		
        if(tab1)
        {
			if(prd_frm == "")
			{
				alert("Please Provide Period From");
				$('#prd_frm').focus();
				$('#dataTable').html('');
				return false;
			}
			if(prd_to == "")
			{
				alert("Please Provide Period To");
				$('#prd_to').focus();
				$('#dataTable').html('');
				return false;
			}
			if(!Date_Compare(prd_to, prd_frm, $("#dt_fmt").val()))
			{
				alert("To Date Must be Greater than From Date");
				$('#prd_to').focus();
				return false;
			}
            if(catgry.sur_id.value == "")
            {
                alert("Please Select Protocol");
                catgry.sur_id.focus();
                return false;
            }
        }
    }
        
	function specimen_data()
	{
        var tab1 = $("#tabs-3").is(":visible");
        if(tab1)
            $("#tab_id").val("1");
		
		prd_frm = $("#prd_frm").val();
		prd_to = $("#prd_to").val();
		sur_id = $("#sur_id").val();
		
        if(tab1)
        {
			if(prd_frm == "")
			{
				alert("Please Provide Period From");
				$('#prd_frm').focus();
				$('#dataTable').html('');
				return false;
			}
			if(prd_to == "")
			{
				alert("Please Provide Period To");
				$('#prd_to').focus();
				$('#dataTable').html('');
				return false;
			}
			if(!Date_Compare(prd_to, prd_frm, $("#dt_fmt").val()))
			{
				alert("To Date Must be Greater than From Date");
				$('#prd_to').focus();
				return false;
			}
            if(sur_id == "")
            {
                alert("Please Select Protocol");
                $("#sur_id").focus();
                return false;
            }
        }
		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&attr=print&sur_id="+sur_id+"&prd_frm="+prd_frm+"&prd_to="+prd_to,
			url: url+"index.php",
			error: function(msg){
				alert( msg.status );
			},
			success: function(msg){
				//alert(msg);
				$('#dataTable').show();
				$('#dataTable').html(msg);
				$('#dataTable').css("border", 0);
				n = msg.indexOf("No menu items to display");
				if(msg != '' && n < 1)
					$("#submit_div").show();
				else
					$("#submit_div").hide();
			}
		});
	}
	
	function div_clear()
	{
		$("#dataTable").hide();
		$("#submit_div").hide();
	}
</script>
<style>
	#dataTable {
		line-height: 15px !important
	}
</style>
<?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);
	
	$dt = date($dt_fmt);
?>
<div style="width: 95%; margin: 0 auto; padding: 10px;">
	<div id="frm_display">
        <div id="tabs">
            <ul>
                <li class="active"><a href="#tabs-3">&nbsp;Lab Chart Report&nbsp;</a></li>
            </ul>
            
            <form class="form" name="recuirtment" id="recuirtment" method="post" action="<?php echo $action; ?>" onsubmit="return frm_validation();" style="width: 100%;">
                <div id="tabs-3">
                    <div class="questionrow" style="width: 50%; margin: 0 auto;">
                        <div class="question"><strong>Period From</strong></div>
                        <div class="answer">
                        	<input type="text" name="prd_frm" id="prd_frm" value="<?php echo $dt; ?>" readonly="readonly" />
                            <input type="hidden" name="prd_frm_old" id="prd_frm_old" value="" />
                            <input type="hidden" name="dt_fmt" id="dt_fmt" value="<?php echo DT_FMT; ?>" />
                            <script>
                                $(function() {
                                    $('#prd_frm').datepick({pickerClass: 'datepick-jumps', 
                                            renderer: $.extend({}, $.datepick.defaultRenderer, 
                                            {picker: $.datepick.defaultRenderer.picker. 
                                                replace(/\{link:prev\}/, '{link:prevJump}{link:prev}'). 
                                                replace(/\{link:next\}/, '{link:nextJump}{link:next}')
                                            }), 
                                            dateFormat: '<?php echo DT_FMT; ?>', 
                                            yearRange: '1900:<?php echo date('Y'); ?>',
                                            showTrigger: '#calImg',
											onClose: showDatefrm
                                    });
                                });
								function showDatefrm(date) {
									prd_frm_old = $("#prd_frm_old").val();
									
									if(prd_frm_old != "" && prd_frm_old != $("#prd_frm").val())
									{
										$("#dataTable").hide();
										$("#submit_div").hide();
										$("#prd_frm_old").val($("#prd_frm").val());
									}
									else
										$("#prd_frm_old").val($("#prd_frm").val());
								}
                            </script>
                        </div>
                        <div class="question"><strong>Period To</strong></div>
                        <div class="answer">
                        	<input type="text" name="prd_to" id="prd_to" value="<?php echo $dt; ?>" readonly="readonly" />
                            <input type="hidden" name="prd_to_old" id="prd_to_old" value="" />
                            <script>
                                $(function() {
                                    $('#prd_to').datepick({pickerClass: 'datepick-jumps', 
                                            renderer: $.extend({}, $.datepick.defaultRenderer, 
                                            {picker: $.datepick.defaultRenderer.picker. 
                                                replace(/\{link:prev\}/, '{link:prevJump}{link:prev}'). 
                                                replace(/\{link:next\}/, '{link:nextJump}{link:next}')
                                            }), 
                                            dateFormat: '<?php echo DT_FMT; ?>', 
                                            yearRange: '1900:<?php echo date('Y'); ?>',
                                            showTrigger: '#calImg',
											onClose: showDateto
                                    });
                                });
								function showDateto(date) {
									prd_to_old = $("#prd_to_old").val();
									
									if(prd_to_old != "" && prd_to_old != $("#prd_to").val())
									{
										$("#dataTable").hide();
										$("#submit_div").hide();
										$("#prd_to_old").val($("#prd_to").val());
									}
									else
										$("#prd_to_old").val($("#prd_to").val());
								}
                            </script>
                        </div>
                        <div class="question"><strong>Protocol&nbsp; &nbsp; </strong></div>
                        <div class="answer">
                        	<?php echo $common->dropdown('sur_code', 'sur_title', 'custom_survey_master', '', 'sur_title', 'sur_id', $sur_id, 'onchange="return div_clear();"'); ?>
                        </div>
                    </div>
                    <div class="clear_form">
                    </div>
                    <div class="questionrow" align="center">
						<br/><input type="button" name="print" value="Go" onclick="return specimen_data();" /><br/><br/>
                    </div>
					<div class="questionrow" id="dataTable" style="display: none; overflow: auto; width: 100%; max-height: 350px;">
					</div>
					<div class="clear_form">
					</div>
                    <div class="questionrow">
                        <div style="padding: 5px; display: none;" align="center" id="submit_div">
                            <input type="submit" name="excel" value="Excel" />
                            <input type="submit" name="pdf" value="Pdf" />
                        </div>
                    </div>
                </div>
            </form>
		</div>
	</div>
</div>