<script language="javascript">
	var asInitVals = new Array();
	
	$(document).ready(function() {
		
		$("#partcpnt_id").autocomplete("autocomplete.php", {
			width: 260,
			matchContains: true,
			//mustMatch: true,
			//minChars: 0,
			//multiple: true,
			highlight: false,
			//multipleSeparator: ",",
			//onItemSelect:selectItem,
			//formatItem:formatItem,
			autoFill: false,
			scroll: true,
			scrollHeight: 180
			/*selectFirst: true,
			scroll: true,
			scrollHeight: 180*/
		});
		
		$("#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 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;
		
		
		/*if(frmname.location.value == "")
		{
			alert("Please Provide Report Type");
			frmname.location.focus();
			return false;
		}*/
	}
	
	
	
	function frm_validation()
	{
		if(navigator.appName != "Microsoft Internet Explorer")
			frmname = document.recuirtment;
		
		var tab3 = $("#tabs-3").is(":visible");
		
		if(tab3)
			$("#tab_id").val("3");
		
		if(tab3)
		{
			if(frmname.partcpnt_id.value == "")
			{
				alert("Please Provide Participant ID");
				frmname.partcpnt_id.focus();
				return false;
			}
			if(frmname.cupn.value == "")
			{
				alert("Please Provide No of Coupons");
				frmname.cupn.focus();
				return false;
			}
			else
			{
				for(i=0; i<frmname.cupn.value; i++)
				{
					cupn_lst = $("#cupn_lst_"+i);
					if(cupn_lst.val() == "")
					{
						alert("Please Provide Coupon Code");
						cupn_lst.focus();
						return false;
					}
					else
					{
						var Pattern = /^[A-Z]{2}[0-9]{4}$/;
						if(!$("#cupn_lst_"+i).val().match(Pattern))
						{
							alert("Please Provide Valid Coupon Code");
							cupn_lst.focus();
							return false;
						}
					}
					/*cupn_dt = $("#cupn_dt_"+i);
					if(cupn_dt.value == "")
					{
						alert("Please Provide Coupon Issue Date");
						cupn_dt.focus();
						return false;
					}
					cupn_prd = $("#cupn_prd_"+i);
					if(cupn_prd.value == "")
					{
						alert("Please Provide Coupon Valid Period");
						cupn_prd.focus();
						return false;
					}
					prd_type = $("#prd_type_"+i);
					if(prd_type.value == "")
					{
						alert("Please Provide Coupon Valid Period");
						prd_type.focus();
						return false;
					}
					cupn_vld_dt = $("#cupn_vld_dt_"+i);
					if(cupn_vld_dt.value == "")
					{
						alert("Please Provide Coupon Valid Date");
						cupn_vld_dt.focus();
						return false;
					}*/
				}
			}
			
			/*if(frmname.cupn_lst.value == "")
			{
				alert("Please Provide Coupon List");
				frmname.cupn_lst.focus();
				return false;
			}*/
			if(frmname.cupn_dt.value == "")
			{
				alert("Please Provide Coupon Issue Date");
				frmname.cupn_dt.focus();
				return false;
			}
			if(frmname.cupn_prd.value == "")
			{
				alert("Please Provide Coupon Valid Period");
				frmname.cupn_prd.focus();
				return false;
			}
			if(frmname.prd_type.value == "")
			{
				alert("Please Provide Coupon Valid Period");
				frmname.prd_type.focus();
				return false;
			}
			if(frmname.cupn_vld_dt.value == "")
			{
				alert("Please Provide Coupon Valid Date");
				frmname.cupn_vld_dt.focus();
				return false;
			}
		}
	}
	
	function val_age(bDay)
	{
		bD = bDay.split('-');
		mnth = bD[1];
		days = bD[0];
		yrs = bD[2];
		
		yr = CalAge(mnth, days, yrs);
		
		if(!isNaN(yr))
			$("#age").val(yr);
		// alert(yr);
	}
	
	function date_cal(bDay, intr, mode, i)
	{
		bD = bDay.split('-');
		mnth = bD[1];
		days = bD[0];
		yrs = bD[2];
		
		yr = date_interval(eval(mnth), eval(days), eval(yrs), eval(intr), eval(mode));
		
		// $("#cupn_vld_dt_"+i).val(yr);
		$("#cupn_vld_dt").val(yr);
		// alert(yr);
	}
	
	function addRow_att(tableID, cnt)
	{
		var out = '';
		for(i=1; i<cnt; i++)
		{
			out = out+'<div class="questionrow"><div class="question">Coupons Code '+(i+1)+'</div><div class="answer"><input type="text" name="cupn_lst[]" id="cupn_lst_'+i+'" value="" /></div></div>';
		}
		$("#"+tableID).html(out);
	}
</script>
<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;Coupon Information&nbsp;</a></li>
            </ul>
            
            <form class="form" name="recuirtment" id="recuirtment" method="post" action="<?php echo $action; ?>" onsubmit="return frm_validation();">
                <div id="tabs-3">
                    <div class="questionrow">
                        <div class="question">Particpant ID</div>
                        <div class="answer">
                        	<input type="text" name="partcpnt_id" id="partcpnt_id" value="" />
                        	<?php // echo $common->dropdown('reg_id', 'reg_participant_id', 'custom_participant_registration', '', 'reg_participant_id', 'partcpnt_id', $partcpnt_id, 'class="required"'); ?>
                        </div>
                    </div>
                    <div class="clear_form">
                    </div>
                    <div class="questionrow">
                        <div class="question">No of Coupons</div>
                        <div class="answer">
                            <input type="text" name="cupn" id="cupn" value="1" onkeyup="return acceptDigits(this), addRow_att('cpn_list', this.value);" onblur="return addRow_att('cpn_list', this.value);" />
                        </div>
                    </div>
                    <div class="clear_form">
                    </div>
                    <div class="questionrow">
                        <div class="question">Coupons Code 1</div>
                        <div class="answer">
                            <input type="text" name="cupn_lst[]" id="cupn_lst_0" value="" />
                        </div>
                    </div>
                    <div class="clear_form">
                    </div>
                    <div id="cpn_list">
                    </div>
                    <div class="clear_form">
                    </div>
                    <div class="questionrow">
                        <div class="question">Coupon Issue Date</div>
                        <div class="answer">
                            <input type="text" name="cupn_dt" id="cupn_dt" value="" readonly="readonly" />
                            <a style="cursor: pointer;" onclick="return showCalendar(this,'cupn_dt','%d-%m-%Y');"><img src="includes/images/cal.gif" border="0"/></a>
                        </div>
                    </div>
                    <div class="clear_form">
                    </div>
                    <div class="questionrow">
                        <div class="question">Coupon Validity Period</div>
                        <div class="answer">
                            <input type="text" name="cupn_prd" id="cupn_prd" value="" size="7" />
                            <select name="prd_type" id="prd_type">
                            	<option value="">Select</option>
                                <option value="1">Days</option>
                                <option value="2">Weeks</option>
                                <option value="3">Month</option>
                                <option value="4">Year</option>
                            </select>
                        </div>
                    </div>
                    <div class="clear_form">
                    </div>
                    <div class="questionrow">
                        <div class="question">Coupon Validity Date</div>
                        <div class="answer">
                            <input type="text" name="cupn_vld_dt" id="cupn_vld_dt" value="" readonly="readonly" onfocus="return date_cal($('#cupn_dt').val(), $('#cupn_prd').val(), $('#prd_type').val(), 0)" />
                            <!--<a style="cursor: pointer;" onclick="return showCalendar(this,'cupn_vld_dt','%d-%m-%Y');"><img src="includes/images/cal.gif" border="0"/></a> -->
                        </div>
                    </div>
                    <!--<div class="clear_form">
                        <div class="question">Mobile</div>
                        <div class="answer">
                            <input type="text" name="" id="" value="" />
                        </div>
                    </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>