$(document).ready(function(){
	load_sms_info();
});

function load_sms_info(){
	$("#second_part").load("module/general_notice/sms_account_setup_datatable.php");
}
// ===================
$("#std_Section_trabulation").click(function(){


	var free_sms = $("#free_sms").val();
	var paid_sms = $("#paid_sms").val();
	var sms_rate = $("#sms_rate").val();
	var atd_to_month = $("#atd_to_month").val();
	var atd_from_month = $("#atd_from_month").val();
	
	var atd_to_year = $("#atd_to_year").val();
	var atd_from_year = $("#atd_from_year").val();
	var mod_id = $("#mod_id").val();

	var operation = 'insert';

	var datastr_sc = "free_sms="+free_sms+"&paid_sms="+paid_sms+"&atd_to_month="+atd_to_month+"&atd_to_year="+atd_to_year+"&atd_from_month="+atd_from_month+"&atd_from_year="+atd_from_year+"&sms_rate="+sms_rate;
	
	
	var final_sc = datastr_sc;
	$('#pdf_gen').val(final_sc);
	

	if(free_sms==""){
		alert("Select Free SMS");
		$('#free_sms').focus();
		return false;
	}
	else if(paid_sms==""){
		alert("Select Paid SMS");
		$('#paid_sms').focus();
		return false;
	}
	else if(sms_rate==""){
		alert("Select SMS rate ");
		$('#sms_rate').focus();
		return false;
	}
	
	/*
	else if(atd_from_month==""){
		alert("Select service start month");
		$('#atd_from_month').focus();
		return false;
	}
	*/
	else if(atd_from_year==""){
		alert("Select service start year");
		$('#atd_from_year').focus();
		return false;
	}
	/*
	else if(atd_to_month==""){
		alert("Select service end month");
		$('#atd_to_month').focus();
		return false;
	}
	else if(atd_to_year==""){
		alert("Select service end year");
		$('#atd_to_year').focus();
		return false;
	}
	*/
	else{

		//$(".show_Section_trabulation").load("module/exam/result_publish.php",datastr_sc);

		$.ajax({
			type:"get",
			url:"module/general_notice/ins_sms_account_setup.php",
			data:datastr_sc,
			success:function(result){
				alert(result);
				load_sms_info();
			}
		});
	}
	

});


   
// =======================================

function show_edit_view(data) {
    var fullData = data.split('~');
			
    $('#id_edit').val(fullData[0]);
    $('#free_sms_edit').val(fullData[1]);
    $('#paid_sms_edit').val(fullData[2]);
    $('#sms_rate_edit').val(fullData[3]);

    // $('#modal-table').modal('show');
			
 }

$("#edit_submit").click(function(e){


	var free_sms = $("#free_sms_edit").val();
	var paid_sms = $("#paid_sms_edit").val();
	var sms_rate = $("#sms_rate_edit").val();
	var id = $("#id_edit").val();
	
	var operation = 'update';

	var datastr_sc = "free_sms="+free_sms+"&paid_sms="+paid_sms+"&id="+id+"&sms_rate="+sms_rate;
	
	
	//var final_sc = datastr_sc;
	//$('#pdf_gen').val(final_sc);
	

	if(free_sms==""){
		alert("Select Free SMS");
		$('#free_sms_edit').focus();
		return false;
	}
	else if(paid_sms==""){
		alert("Select Paid SMS");
		$('#paid_sms_edit').focus();
		return false;
	}
	else if(sms_rate==""){
		alert("Select SMS rate ");
		$('#sms_rate_edit').focus();
		return false;
	}
	else{

		$.ajax({
			type:"get",
			url:"module/general_notice/update_sms_account_setup.php",
			data:datastr_sc,
			success:function(result){
				alert(result);
				
				$('#resultUpdateShow').show(500);
				$('#resultUpdate').html(result);
				
			}
		});
		
		 e.preventDefault(); //=== To Avoid Page Refresh and Fire the Event "Click"===
	}
	load_sms_info();
});