function add_admin(){
	
	document.getElementById("output").innerHTML ='<div style="margin-top:10px"><center>Saving Data, please wait...<br/><img src="images/ajax-loader1.gif" width="10%"/></center></div>';
	document.getElementById("saving").style.display = "none";
	var a_full_name=document.getElementById("full_name").value;
	var a_address=document.getElementById("address").value;
	var a_email=document.getElementById("email").value;
	var gender=document.getElementById("gender").value;
	var country=document.getElementById("country").value;
	var state=document.getElementById("state").value;
	var a_phone_number=document.getElementById("phone_number").value;
	var a_rank=document.getElementById("a_rank").value;
	
		var atpos=a_email.indexOf("@");
		var dotpos=a_email.lastIndexOf(".");
		
		
		if( atpos <1 || dotpos < atpos+2 || dotpos+ 2 >= a_email.length ){
		  
			document.getElementById("output").innerHTML ='<center><div class="alert alert-danger alert-dismissible" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><strong>Alert!</strong> invalid email address</div></center>';
			//document.getElementById("saving").innerHTML ='<button type="button" class="btn btn-primary btn-block" onclick="add_admin()">Add</button>';
			document.getElementById("saving").style.display = "block";
		  }else if(a_full_name==""){
			document.getElementById("output").innerHTML ='<div class="alert alert-danger alert-dismissible" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><strong>Alert!</strong> Staff fullname is required</div>';
			document.getElementById("saving").style.display = "block";
			//document.getElementById("saving").innerHTML ='<button type="button" class="btn btn-primary btn-block" onclick="add_admin()">Add</button>';
		}else if(a_address==""){
			document.getElementById("output").innerHTML ='<div class="alert alert-danger alert-dismissible" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><strong>Alert!</strong> Staff address is required</div>';
			//document.getElementById("saving").innerHTML ='<button type="button" class="btn btn-primary btn-block" onclick="add_admin()">Add</button>';
			}else if(a_phone_number==""){
			document.getElementById("output").innerHTML ='<div class="alert alert-danger alert-dismissible" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><strong>Alert!</strong> Staff phone is required</div>';
			//document.getElementById("saving").innerHTML ='<button type="button" class="btn btn-primary btn-block" onclick="add_admin()">Add</button>';
		}else if(a_rank==""){
			document.getElementById("output").innerHTML ='<div class="alert alert-danger alert-dismissible" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><strong>Alert!</strong> Please select staff type </div>';
			//document.getElementById("saving").innerHTML ='<button type="button" class="btn btn-primary btn-block" onclick="add_admin()">Add</button>';
		}else{
			document.getElementById("output").innerHTML ='';
			$.post("php/save_admin.php",{a_full_name:a_full_name,a_email:a_email,a_address:a_address,a_phone_number:a_phone_number,a_rank:a_rank,gender:gender,country:country,state:state},
			function(response,status){ // Required Callback Function
			
				if(response=='1'){
					
					swal("Admin added successfully");
					document.getElementById("saving").style.display = "block";
				}else{
				document.getElementById("output").innerHTML =response;
				document.getElementById("saving").style.display = "block";
		
					}
			});
		}
}



function add_cat(){
	document.getElementById("output").innerHTML ='<div style="margin-top:10px"><center>Saving Data, please wait...<br/><img src="images/ajax-loader1.gif" width="10%"/></center></div>';
	document.getElementById("saving").style.display = "none";
	var cat_name=document.getElementById("cat_name").value;
	if(cat_name==""){
			document.getElementById("output").innerHTML ='<div class="alert alert-danger alert-dismissible" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><strong>Alert!</strong> Please Category Name </div>';
			document.getElementById("saving").style.display = "block";
	}else{
		
			document.getElementById("output").innerHTML ='';
			$.post("php/save_category.php",{cat_name:cat_name},
			function(response,status){ // Required Callback Function
			
				if(response=='1'){
					
					swal("Category added successfully");
					document.getElementById("saving").style.display = "block";
					window.setTimeout(links_cat, 2000);
					
				}else{
					document.getElementById("output").innerHTML =response;
					document.getElementById("saving").style.display = "block";
		
					}
			});
		
	}
	
	
}





function links_cat(){
	 window.location.href = "dashboard?machines=category";
 }
	
		