var thisInitialCost=0;
var thisdiscount=0;
var thisOurSerial = '';
/*var thisCheckId=0;
var thisDetailId=0;
*/
 $(".check").click(function(){
	 $i = this.id;
	 thisInitialCost=$(this).attr('data-initialcost');
	 thisOurSerial=$(this).attr('data-ourSerial');
	 showcheckReportModalBox($i);
	 document.getElementById('initialCost'+$i).innerHTML=thisInitialCost;
	 
	$.ajax({
						type: 'POST',
						url: 'checkReportControllerAjax.php?do=loadCosts&ourSerial='+thisOurSerial,
						//data: $("#checkReportInfo"+$i).serialize(),
						success: function(data) {
							//alert(data);
							$("#allCostsDiv").html(data);
								
							
						}
							
						
					});
					
	$.ajax({
						type: 'POST',
						url: 'checkReportControllerAjax.php?do=getdDiscount&ourSerial='+thisOurSerial,
						//data: $("#checkReportInfo"+$i).serialize(),
						success: function(data) {
							
							document.getElementById('discount').value=data;
								
							
						}
							
						
					});
	
 });
	 
 $(".closeReport").click(function(){
	 $i = this.id;
	 //alert($i);
	 closeCheckReportModal($i);
 });
	 
 $('.insertcheckReport').click(function(e) {
	//alert(thisOurSerial);
	$.ajax({
						type: 'POST',
						url: 'checkReportControllerAjax.php?do=makeDiscount&ourSerial='+thisOurSerial,
						data: $("#checkReportInfo2").serialize(),
						success: function(data) {
							//alert(data);
							document.getElementById('discount').style.backgroundColor='#B4F6B4';
								
							
						}
							
						
					});
});

 
////// Adding new check report with modal box /////////////

function showcheckReportModalBox($i)
{
	$('#checkReportModal'+$i).modal('show');
	emptycheckReportModalForm($i);
	

}


function emptycheckReportModalForm($i)
{
	$('#checkReportInfo2').find(':input').each(function(){
		var type = this.type, tag = this.tagName.toLowerCase();
		if (type == 'text' || type == 'password' || tag == 'textarea')
			this.value = '';
		else if (type == 'checkbox' || type == 'radio')
			this.checked = false;
		
	});
	document.getElementById('discount').style.backgroundColor='white';
}


function closeCheckReportModal($i)
{
	$('#checkReportModal'+$i).modal('hide');
	emptycheckReportModalForm($i);
}

function andPay()
{
	//alert('change attr');
	$("#delevery").attr("action","deleveryReportController.php?do=deleverandPay");
	return true;
}


/////////////////////////////////////////////////////////////////////////////////////////////
//                                  srtop many submits                                     //
/////////////////////////////////////////////////////////////////////////////////////////////

$("#delevery").submit(function(ev) {
	
//alert('submit');	
	
// submit more than once return false
$(this).submit(function() {

return false;
});
// submit once return true


return true;
});

