$(function(){
	
	
 
$user_type='';	
		

$("#add_priv").click(function(){
	
if($("#depart").val()==""){
alert("حدد نوع المستخدم");
exit();
}	

$user_type=$("#depart").val();

$("#big-div-cont").show();	
$("#over").show();	
});

$("#close").click(function(){
$("#big-div-cont").hide();	
$("#over").hide();
});



$("#priv_table_select_btn").click(function(){
if($("#priv_table_select").attr("value")==''){
alert("اختار الجدول")	
exit();
}
$rand_id=10000 + Math.floor(Math.random() * 99999);
$table=$("#priv_table_select").attr("value");
$name=$('#priv_table_select').find(":selected").text();
//alert($user_type);
if($user_type=="2"){
x="<tr class='table_tr' id='"+$table+"_"+$rand_id+"'><td><input name='table' type='hidden' value='"+$table+"' />"+ $name + " </td><td><select name='"+$table+"_1' ><option value='0' style='background:#E8B2B2'>منع</option><option value='1' style='background:#B1D69A'>سماح</option> </select></td><td><select name='"+$table+"_2' ><option value='0' style='background:#E8B2B2'>منع</option><option value='1' style='background:#B1D69A'>سماح</option> </select></td><td><select name='"+$table+"_3' ><option value='0' style='background:#E8B2B2'>منع</option><option value='1' style='background:#B1D69A'>سماح</option> </select></td><td><select name='"+$table+"_4' ><option value='0' style='background:#E8B2B2'>منع</option><option value='1' style='background:#B1D69A'>سماح</option> </select></td> <td><select name='"+$table+"_5' ><option value='0' style='background:#E8B2B2'>منع</option><option value='1' style='background:#B1D69A'>سماح</option> </select></td> <td align='center'><a class='delete_priv_row' table_name='$table' alt='"+$table+"_"+$rand_id+"'><img src='../img/delete.png'></td></tr>";
}else if($user_type=="1"){
x="<tr class='table_tr' id='"+$table+"_"+$rand_id+"'><td><input name='table' type='hidden' value='"+$table+"' />"+ $name + " </td><td><select name='"+$table+"_1' ><option value='0' style='background:#E8B2B2'>منع</option><option value='1' style='background:#B1D69A' selected >سماح</option> </select></td><td><select name='"+$table+"_2' ><option value='0' style='background:#E8B2B2'>منع</option><option value='1' style='background:#B1D69A' selected >سماح</option> </select></td><td><select name='"+$table+"_3' ><option value='0' style='background:#E8B2B2'>منع</option><option value='1' style='background:#B1D69A' selected >سماح</option> </select></td><td><select name='"+$table+"_4' ><option value='0' style='background:#E8B2B2'>منع</option><option value='1' style='background:#B1D69A' selected >سماح</option> </select></td> <td><select name='"+$table+"_5' ><option value='0' style='background:#E8B2B2'>منع</option><option value='1' style='background:#B1D69A' selected >سماح</option> </select></td> <td align='center'><a class='delete_priv_row' table_name='$table' alt='"+$table+"_"+$rand_id+"'><img src='../img/delete.png'></td></tr>";	
}

//alert(x);
$("#priv_table").append(x);	
$('#priv_table_select').find(":selected").hide();
$("#priv_table_select option:first").attr('selected','selected');
});



$(".delete_priv_row").live("click",function(){

	
$("#"+$(this).attr("alt")).remove();	
});



$("#submit_priv").live("click",function(){
$method=$(this).attr("method");	
$id=$(this).attr("record");	
$tables='';	
$("input[type=hidden]").each(function() {
$tables+=$(this).val()+",";
});
	
	

$.post("ajax_add_priv.php",{"data":$("#form_insert").serialize(),"tables":$tables,"method":$method,"id":$id}
,function(data){
//alert(data);
$("#form_insert").submit();
if (err==0){
alert("تم الادخال بنجاح")	;
}else if(err==1){
alert("لم ينجح الادخال")	;
}
 });

	

});








});
