$(function(){
total_con=$("#total_con").text();
total_rows=$("#total_rows").text();
max_con=$("#max_con").text();
cat_id=$("#depart_select").attr("cat");
cat_name=$("#cat_name").attr("value");
current_con=1;
i=0;







////////////////////////////next_search/////////////////////////////
////////////////////////////next_search/////////////////////////////


$("#next_num_search").live("click",function(){

	
if(current_con<total_con){

current_con++;
table=$(this).attr("lang");
num_rows=$(this).attr("max");
search=$(this).attr("search");
end=(Math.round((eval(current_con)))* Math.round((eval(num_rows))))-1;
start=Math.round((eval(end)))-(Math.round((eval(num_rows)))-1);

comp=$(this).attr("comp");
depart='0';


current_mod=(current_con-1)%max_con;

//فى حالة عدم وجود الرقم التالى
if(current_mod!=0){
$(".num_con_search").removeClass("num_active");
$("#num_con_search"+current_con).addClass("num_active");
$("#next_num_search").attr("alt",Math.round((eval($("#next_num_search").attr("alt"))))+1);	
$("#prev_num_search").attr("alt",Math.round((eval($("#prev_num_search").attr("alt"))))+1);
$(".se-pre-con").hide();
$('body').animate({ scrollTop: 0 }, 'slow');	
}else{


from=Math.round((eval((current_con))))-1 + Math.round((eval((max_con)))) ;
to=(Math.round((eval(from)))-Math.round((eval(max_con))))+1;	

//alert(from);
//alert(to);
$(".num_con_search").show();
for(i=from;i>=to;i--){
before=i-max_con;

$("#num_con_search"+before).attr("alt",i);
$("#num_con_search"+before).text(i);
$("#num_con_search"+before).attr("id","num_con_search"+i);	

if(i>total_con){ $("#num_con_search"+i).hide(); }
}

$(".num_con_search").removeClass("num_active");
$("#num_con_search"+current_con).addClass("num_active");

}

page=$("#load_page").html();
page=page+".php";
//$("#load_wait").show();
$(".se-pre-con").show();

$("#result_view").load(page,{
"cat_id": cat_id,
'search':search ,
"table":table ,
"start":start, 

"end":end ,
"num_rows":num_rows ,
"cat_id":cat_id ,
"cat_name":cat_name,
"comp":comp,
"depart":depart 
},function(){

if (end>total_rows){ end=total_rows	}
$("#rows_range").html((end+1)+"-"+(start+1));

//$("#load_wait").hide();
$(".se-pre-con").hide();
$('body').animate({ scrollTop: 0 }, 'slow');	


	
});
}

});









////////////////////////////prev_search/////////////////////////////
////////////////////////////prev_search/////////////////////////////



$("#prev_num_search").live("click",function(){	
//alert(current_con);

if(current_con>1){
current_con--;
table=$(this).attr("lang");
num_rows=$(this).attr("max");
search=$(this).attr("search");
comp=$(this).attr("comp");
depart='0';
end=(Math.round((eval(current_con)))* Math.round((eval(num_rows))))-1;
start=Math.round((eval(end)))-(Math.round((eval(num_rows)))-1);

current_mod=(current_con)%max_con;
comp=$(this).attr("comp");
depart='0';
//فى حالة عدم وجود الرقم التالى
if(current_mod!=0){
$(".num_con_search").removeClass("num_active");
$("#num_con_search"+current_con).addClass("num_active");
$("#next_num_search").attr("alt",Math.round((eval($("#next_num_search").attr("alt"))))-1);	
$("#prev_num_search").attr("alt",Math.round((eval($("#prev_num_search").attr("alt"))))-1);

//alert(current_con);
}else{
//alert("sss");
from=current_con ;
to=Math.round((eval((current_con))))-Math.round((eval((max_con))))+1;	
//alert(from);
//alert(to);
$(".num_con_search").show();
for(i=from;i>=to;i--){
before=Math.round((eval(i)))+Math.round((eval(max_con)));

$("#num_con_search"+before).attr("alt",i);
$("#num_con_search"+before).text(i);
$("#num_con_search"+before).attr("id","num_con_search"+i);	

if(i>total_con){ $("#num_con_search"+i).hide(); }
}

$(".num_con_search").removeClass("num_active");
$("#num_con_search"+current_con).addClass("num_active");

}

page=$("#load_page").html();
page=page+".php";
//$("#load_wait").show();
$(".se-pre-con").show();

$("#result_view").load(page,{
"cat_id": cat_id,
'search':search ,
"table":table ,
"start":start ,
"end":end ,
"num_rows":num_rows ,
"cat_id":cat_id ,
"cat_name":cat_name,
"comp":comp,
"depart":depart
},function(){

if (end>total_rows){ end=total_rows	}
$("#rows_range").html((end+1)+"-"+(start+1));
//$("#load_wait").hide();
$(".se-pre-con").hide();
$('body').animate({ scrollTop: 0 }, 'slow');	


	
});


}

});







////////////////////////////num_con_search/////////////////////////////
////////////////////////////num_con_search/////////////////////////////

$(".num_con_search").live("click",function(){
total_con=$("#total_con").text();
if ($(this).attr("class")!='num_con_search num_active'){

$(".num_con_search").removeClass("num_active");
$(this).addClass("num_active");

current_con=$(this).attr("alt");
table=$(this).attr("lang");
num_rows=$(this).attr("max");
search=$(this).attr("search");
comp=$(this).attr("comp");
depart='0';
page=$("#load_page").html();
page=page+".php";
//$("#load_wait").show();
//$(".se-pre-con").show();

end=(Math.round((eval(current_con)))* Math.round((eval(num_rows))))-1;
start=Math.round((eval(end)))-(Math.round((eval(num_rows)))-1);

//alert(current_con);
//alert(table);
//alert(num_rows);
//alert(search);
//alert(page);
//alert(end);
//alert(start);
//alert(comp);
//alert(depart);


$("#next_num").attr("alt",Math.round((eval(current_con)))+1);
$("#prev_num").attr("alt",Math.round((eval(current_con)))-1);

//$("#load_wait").show();
$(".se-pre-con").show();
//alert("xx");
$("#result_view").load(page,{
"cat_id": cat_id,
'search':search ,
"table":table ,
"start":start ,
"end":end ,
"num_rows":num_rows,
"comp":comp,
"depart":depart 
},function(){
//$("#load_wait").hide();
$(".se-pre-con").hide();
$('body').animate({ scrollTop: 0 }, 'slow');	


});	

}
//alert("S");
});



////////////////////////////depart_list/////////////////////////////
////////////////////////////depart_list/////////////////////////////



$("#depart_select").bind("change",function(){
total_con=$("#total_con").text();

current_con=$(this).attr("alt");
table=$(this).attr("lang");
num_rows=$(this).attr("max");
search=$(this).attr("search");
comp=$(this).attr("comp");
depart=$(this).val();
page=$("#load_page").html();
page=page+".php";

cat_id=$(this).val();
//$("#load_wait").show();


end=0;
start=0;

//alert(current_con);
//alert(table);
//alert(num_rows);
//alert(search);
//alert(page);
//alert(end);
//alert(start);
//alert(cat_id);
//alert(depart);



//$("#load_wait").show();
$(".se-pre-con").show();

$("#result_view").load(page,{
"cat_id": cat_id,
'search':search ,
"table":table ,
"start":start ,
"end":end ,
"num_rows":num_rows ,
"comp":comp , 
"depart":depart
},function(){
	

	//alert("xxx");
$("#num_container").load("ajax_num_container.php",{
"table":table ,
'search':search ,
"comp":comp ,
"depart":depart,
"cat_id": cat_id,
"num_rows":num_rows
	
},function(){ 

$("#num_rows").html($("#total_con").html());

});


	
//$("#load_wait").hide();
$(".se-pre-con").hide();
$('body').animate({ scrollTop: 0 }, 'slow');	

});	


});














	
});


