/**********************************Main Validation *******************************************************/
function book_main_validation()
{
    var from_party_name = document.getElementById("from_party_name").value;
	if(from_party_name=='')
	{
		document.getElementById("from_party_name_valid_div").innerHTML="* This field is Required.";
		document.getElementById("from_party_name").focus();
		return false;
	}
	
	var to_party_name = document.getElementById("to_party_name").value;
	if(to_party_name=='')
	{
		document.getElementById("to_party_name_valid_div").innerHTML="* This field is Required.";
		document.getElementById("to_party_name").focus();
		return false;
	}
	
	var overal_tot = document.getElementById("overal_tot").value;
	if(overal_tot=='')
	{
		alert("Please Fill The Sublist");
		document.getElementById("book_particulars").focus();
		return false;
	}
	
	var tot_amt = document.getElementById("tot_amt").value;
	if(tot_amt=='')
	{
		alert("Need S.T charge");
		document.getElementById("st_charges").focus();
		return false;
	}
	
	/*var from_mob_no = document.getElementById("from_mob_no").value;
	var to_party_mob = document.getElementById("to_party_mob").value;
	if((from_mob_no==to_party_mob)&&((from_mob_no||to_party_mob)!=''))
	{
		alert("From Party and to party Mob No are same");
		document.getElementById("to_party_name").focus();
		return false;
	}*/
}

function book_main_clear_valid(str)
{
	if(str!='')
	{
		document.getElementById("from_party_name_valid_div").innerHTML="";
	}
	if(str!='')
	{
		document.getElementById("to_party_name_valid_div").innerHTML="";
	}
		
}
/********************* Check To party name (if same with from party name)********************************************/ 
 function get_to_party_name()
 {
    var from_party_name = document.getElementById("from_party_name").value;
	var to_party_name = document.getElementById("to_party_name").value;
	
									if(from_party_name==to_party_name)
									{
									document.getElementById('to_party_name').value='';
									document.getElementById('to_party_address').value='';	
									document.getElementById('to_party_mob').value='';
									}
 }
/********************************** Sublist Validation *******************************************************/
function book_sub_validation()
{
	
	var from_party_name = document.getElementById("from_party_name").value;
	if(from_party_name=='')
	{
		document.getElementById("from_party_name_valid_div").innerHTML="* This field is Required.";
		document.getElementById("from_party_name").focus();
		return false;
	}
	
	var to_party_name = document.getElementById("to_party_name").value;
	if(to_party_name=='')
	{
		document.getElementById("to_party_name_valid_div").innerHTML="* This field is Required.";
		document.getElementById("to_party_name").focus();
		return false;
	}
	
    var book_particulars = document.getElementById("book_particulars").value;
	if(book_particulars=='')
	{
		document.getElementById("book_particulars_valid_div").innerHTML="* This field is Required.";
		document.getElementById("book_particulars").focus();
		return false;
	}
}

function book_sub_clear_valid(str)
{
	if(str!='')
	{
		document.getElementById("from_party_name_valid_div").innerHTML="";
	}
	if(str!='')
	{
		document.getElementById("to_party_name_valid_div").innerHTML="";
	}
	
	if(str!='')
	{
		document.getElementById("book_particulars_valid_div").innerHTML="";
	}
	
}
/**************** Sublist Add ***********************************/
function booking_sub_list(book_no,from_party_name,to_party_name,booking_date,booking_place,booking_branch,pay_to_pay_val,book_particulars,weight_kg,rates,freight_rs,edit_id,action)
{ 
if((from_party_name)&&(to_party_name)&&(book_particulars!=''))
 {
  jQuery.ajax({
		type: "POST",
		url: "booking/booking_entry/booking_entry_db.php",
		data: "book_no="+book_no+"&from_party_name="+from_party_name+"&to_party_name="+to_party_name+"&booking_date="+booking_date+"&booking_place="+booking_place+"&booking_branch="+booking_branch+"&pay_to_pay_val="+pay_to_pay_val+"&book_particulars="+book_particulars+"&weight_kg="+weight_kg+"&rates="+rates+"&freight_rs="+freight_rs+"&edit_id="+edit_id+"&action="+action,
		success: function(msg){jQuery("#book_sub_list_div").html(msg);
		document.getElementById("book_particulars").value='';
		document.getElementById("weight_kg").value='';
		document.getElementById("rates").value='';
		document.getElementById("freight_rs").value='';
		document.getElementById('add').value='ADD';
	    document.getElementById("st_charges").focus();	
		document.getElementById("book_particulars").focus();	
 }
		});
}
else
{
    book_sub_validation();
}
}
/******************************************** SUB EDIT*****************************************************************/
function edit_booking_sub(edit_id,book_no)
{ 
  jQuery.ajax({
		type: "POST",
		url: "booking/booking_entry/booking_sublist.php",
		data: "edit_id="+edit_id+"&book_no="+book_no,
		success: function(msg){jQuery("#book_sub_list_div").html(msg);

 }
		});
}
/******************************************** SUB DELETE*****************************************************************/
function del_book_sub(id,book_no,action)
{
	if(confirm('Are You Sure! You Want To Delete?'))
	{
		jQuery.ajax({
		type: "POST",
		url: "booking/booking_entry/booking_entry_db.php",
		data: "id="+id+"&book_no="+book_no+"&action=del_book_sublist",
		success: function(msg){jQuery("#book_sub_list_div").html(msg);
		 document.getElementById("st_charges").focus();	
		document.getElementById("book_particulars").focus();	
	}
	});
    }
}
/*************************main list********************************************/
function booking_main_list(book_no,booking_date,booking_place,booking_branch,pay_to_pay_val,from_party_name,from_address,from_mob_no,to_party_name,to_party_address,to_party_mob,st_charges,tot_amt,overal_tot,remarks,edit_id,action)
{ 
if((from_party_name!='')&&(to_party_name!='')&&(st_charges!='')&&(overal_tot!=''))
 {
  jQuery.ajax({
		type: "POST",
		url: "booking/booking_entry/booking_entry_db.php",
		data: "book_no="+book_no+"&booking_date="+booking_date+"&booking_place="+booking_place+"&booking_branch="+booking_branch+"&pay_to_pay_val="+pay_to_pay_val+"&from_party_name="+from_party_name+"&from_address="+from_address+"&from_mob_no="+from_mob_no+"&to_party_name="+to_party_name+"&to_party_address="+to_party_address+"&to_party_mob="+to_party_mob+"&st_charges="+st_charges+"&tot_amt="+tot_amt+"&overal_tot="+overal_tot+"&remarks="+remarks+"&edit_id="+edit_id+"&action="+action,
		success: function(msg){jQuery("#booking_main_list_div").html(msg);
		// alert(msg);
		 //window.close();
		 window.location.reload(true);
		 
		 if(edit_id!='')
		 { 
		     window.location.reload(true);
			 window.location.href="main_fram.php?file=booking_creation_list";
		 }
  	    
 }
		});
}
else
{
    book_main_validation();
	
}
}

/*************************** Delete sublist entry without mainlist entry********************************************************/
/*function delete_book_no_sub(book_number)
{
	alert("book_number="+book_number);
	jQuery.ajax({
		type: "POST",
	  	url: "booking/booking_entry/delete_book_sub.php",
		data: "book_number="+book_number,
		success: function(msg){jQuery("#booking_no_sub_div").html(msg);
	      }
		});
}*/
/**************************** Get Frieght amt************************************************/
function get_fright_amt(weight_kg,rates)
{
	var freight_amt=weight_kg*rates;
	document.getElementById("freight_rs").value=freight_amt;
}
/****************************Get Total Amt************************************************/
function get_st_total(overal_tot,st_charges)
{
	var a=overal_tot;
	var b=st_charges;
	var tot_amt=(+a) + (+b);
	document.getElementById("tot_amt").value=tot_amt;
}
/**************************** Get from party address************************************************/
function get_party_address(from_party_name)
{
		jQuery.ajax({
		type: "POST",
		url: "booking/booking_entry/from_addres.php",
		data: "from_party_name="+from_party_name,
		success: function(msg){jQuery("#party_adres_div").html(msg);
	}
	});
}
/**************************** Get from party mob no************************************************/
function get_party_mob(from_party_name)
{
		jQuery.ajax({
		type: "POST",
		url: "booking/booking_entry/from_mob.php",
		data: "from_party_name="+from_party_name,
		success: function(msg){jQuery("#party_mob_div").html(msg);
	}
	});
}
/**************************** Get to party addres************************************************/
function get_to_party_address(to_party_name,from_mob_no)
{
		jQuery.ajax({
		type: "POST",
		url: "booking/booking_entry/to_addres.php",
		data: "to_party_name="+to_party_name,
		success: function(msg){jQuery("#party_to_adres_div").html(msg);
	}
	});
	
	jQuery.ajax({
		type: "POST",
		url: "booking/booking_entry/to_mob.php",
		data: "to_party_name="+to_party_name,
		success: function(msg){jQuery("#party_to_mobile_div").html(msg);
									
}
			
	});
}
/******************************main list delte*******************************************/
function del_book_main(id,booking_no)
{
	if(confirm('Are You Sure! You Want To Delete?'))
	{
		jQuery.ajax({
		type: "POST",
		url: "booking/booking_entry/booking_entry_db.php",
		data: "id="+id+"&booking_no="+booking_no+"&action=delete_book_main",
		success: function(msg){jQuery("#booking_main_list_div").html(msg);
		window.location.reload(true);
	}
	});
    }
}
