/* Выделение чекбоксов сайтов с кнопкой Shift */
function shiftCheck(i,e,id){
	pred=document.getElementById('i').getAttribute("i");
	if(pred<i){min=pred;max=i}else{min=i;max=pred}
	if(window.childContentChkBoxs){childContentChkBoxs(id)}
	if(e.shiftKey){$(".check").each(function(){var id=$(this).attr("id");
	var j=id.substring(3,id.length);
	if(document.getElementById('id_'+j+'')){temp=parseInt(document.getElementById('id_'+j+'').getAttribute("i"));
	if(min<temp&&temp<max){if(document.getElementById('id_'+j+'').checked){document.getElementById('id_'+j+'').checked=false;$('#id_'+j).parent().parent().removeClass("checked_row")}else{document.getElementById('id_'+j+'').checked=true;
	$('#id_'+j).parent().parent().addClass("checked_row")}}}})}var newAttr=document.createAttribute("i");
	newAttr.nodeValue=i;document.getElementById("i").setAttributeNode(newAttr);
} 
/* Выделение чекбоксов сайтов с кнопкой Shift */
FLAG = false;
function Construct() {
	var new_top = getClientCenterY()-25;
	var new_left = getClientCenterX()-25;
	$('#loading').css({'top':new_top+'px','left':new_left +'px','visibility':'visible','z-index':'2000'});
	$("#info").html(CREATE_TABLE);
	$.post("index.php",{act:"tablea"},function(data){
	if (data.table['icons'] != 0) FLAG = true;
	if (data.table['footer'] != 0)
	{
		function screen() {var height = ($(window).height() - 180);
		var count = (data.table['count'] * 26)+25;
		if (count<height){return 'auto'}else{return height}};
	}
	else
	{
		function screen() {var height = ($(window).height() - 130);
		var count = (data.table['count'] * 26)+25;
		if (count<height){return 'auto'}else{return height}};
	}
	var table = '<table cellpadding="0" cellspacing="0" width="100%" align="center" border="0" class="content"><tr><td class="content_top_left"><img src="skins/default/space.png"/></td><td rowspan="3"><table id="tablea" class="static" height="'+screen()+'" border="0" cellpadding="0" cellspacing="0" width="100%">';
	if (data.table['scroll'] != 0) table += '<thead class="scrolltable">';
	else  table += '<thead>';
	table += '<tr class="fixed header"><th align="center" width="10" class="{sorter: false}"><div id="i" i=""></div><input type="checkbox" name="checkAll" id="checkAll" value="checkbox"></th><th width="10" class="{sorter: false}">&nbsp;</th><th width="10" class="{sorter: false}">&nbsp;</th>';
	if (data.table['icons'] != 0) table += '<th width="16" class="{sorter: false}">&nbsp;</th>';
	table += '<th class="{sorter: \'text\'}"><span class="action">URL</span></th>';
	if (data.table['group'] != 0) table += '<th class="{sorter: \'text\'}"><span>'+GROUP+'</span></th>';
	if (data.table['topTable'] != undefined) table += data.table['topTable'];
	table += '<th align="center" class="{sorter: false}">'+ACTION+'</th>';
	if (data.table['scroll'] != 0) table += '</tr></thead><tbody class="scrolltable" id="siterow"></tbody>';
	else  table += '</tr></thead><tbody id="siterow"></tbody>';	
	table += '<tfoot class="footer scrolltable"><tr class="fixed"><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>';
	if (data.table['icons'] != 0) table += '<td>&nbsp;</td>';
	table += '<td>&nbsp;</td>';
	if (data.table['group'] != 0) table += '<td>&nbsp;</td>';
	if (data.table['footTable'] != undefined) table += data.table['footTable'];
	table += '<td>&nbsp;</td></tr></tfoot></table></td><td class="content_top_right">&nbsp;</td></tr><tr><td class="content_left">&nbsp;</td><td class="content_right">&nbsp;</td></tr><tr><td class="content_left" valign="bottom"><div class="content_bottom_left"></div></td><td class="content_right" valign="bottom"><div class="content_bottom_right"><img src="skins/default/space.png"/></div></td></tr></table>';
	var rank=data.table['rankStr'];
	if (data.table['footer'] != 0) $('#all').html(data.table['count']);

	$("#construct").html(table);
	
	$.each(data.row,function(i,val){
		
		var row = '<tr id="cont_'+val['id']+'" i="'+val['i']+'" class="parent">';
		row += '<td align="center" id="'+val['id']+'_id" width="10"><input type="checkbox" name="id_'+val['id']+'" id="id_'+val['id']+'" i="'+val['i']+'" onclick="shiftCheck('+val['i']+',event,'+val['id']+');" class="check" /></td>';
		row += '<td width="10" id="'+val['id']+'_num" align="center" class="dragHandle"><span id="num_'+val['id']+'">'+val['i']+'</span></td>';
		row += '<td class="row non_checked" width="10" id="'+val['id']+'_arrow"><div class="arrow" value="'+val['id']+'">&nbsp;</div></td>';
		if (val['icons'] != 0) row += '<td class="icons" id="'+val['id']+'_icons"><img src="http://favicon.yandex.net/favicon/'+val['url']+'" width="16" height="16"></td>';
		row += '<td valign="middle" class="url" id="'+val['id']+'_url"><a href="http://'+val['url']+'" target="_blank">'+val['url']+'</a></td>';
		if (data.table['group'] != 0) {if (val['group'] == null)  row += '<td align="center" class="group" id="'+val['id']+'_group"><div class="empty"><span>0</span></div></td>';
		else row += '<td align="center" class="group" id="'+val['id']+'_group"><span>'+val['group']+'</span></td>';
		}
		if (val['module'] != 0) row += val['module'];
		if (val['scrolling'] != 0) row += '<td align="center" width="64" class="non_checked" id="'+val['id']+'_action" style="padding-right:15px;"><table cellpadding="0" cellspacing="0" border="0" height="16" width="100%"><tr class="act_but">';
		else row += '<td align="center" width="64" class="non_checked" id="'+val['id']+'_action"><table cellpadding="0" cellspacing="0" border="0" height="16" width="100%"><tr class="act_but">';
		if (val['action'] != 0) row += val['action'];
		if (val['guest'] != 1) row += '<td><div onclick="delDomen(\''+val['id']+'\');" class="remove_site" title="'+DELEETE_SITE+'">&nbsp;</div></td>';
		row += '</tr></table></td></tr>';


		$("#siterow").append(row);
	}); 
	tablea(rank);
	if (data.table['topTable'] != undefined) CreateTable();
	$("#loading").css("visibility","hidden");
	$("#info").html("");
	},"json");

}

function ProgressBar(counter){
	$("#info").html(counter+"%");
	$("#count").css('width',counter+'%');
	if (counter>99) {
	var counter = 0;
	$("#loading").css("visibility","hidden");
	$("#loader").css({'width':'0px','height':'0px','border':'none'});
	$("#count").css('width','0px');
	$("#info").css('width','0px');
	$("#tablea").tablesorter({widgets: ['zebra']});
	} 
};

function addDomen(){
	var url=document.getElementById("url").value;
	if (trim(url).length>0) { 
		var d2=document.getElementById("d2").value;
		document.getElementById("url").value="";
		var new_top = getClientCenterY()-25;
		var new_left = getClientCenterX()-25;
		$('#loading').css({'top':new_top+'px','left':new_left +'px','visibility':'visible','z-index':'2000'});
		$("#info").html(ADD);
		$.post("index.php",{act:"add_domen",url:""+url+"",d2:""+d2+""},function(data){
		$("#loading").css("visibility","hidden");
		$("#info").html("")
			if(trim(data).length>0){
				$.modal(data, {autoResize:true});
			}else{
				Refresh(['top']);
				Construct();
			}
		});
	}
	else {
		alert (DOMEN_EMPTY)
	}
}

function synch(){
	document.getElementById("act").options[document.getElementById("act2").selectedIndex].selected=true
}

function List(){
	var str="";
	var checkbox="";
	$(".check").each(function(){
		if((this).checked){
		var id=$(this).attr("id");
		checkbox+=id.substring(3,id.length)+",";
		str+=jQuery(this).parent().parent().find("td a").eq(0).text()+"\n";
	}});
	var act=document.getElementById("act").value;
	checkbox=checkbox.substring(0,checkbox.length-1);
	if(isNaN(act)){
		if(act=='getallsites') {
			if(str!="") {
				$.modal('<textarea rows="10" cols="50">'+str+'</textarea>', {autoResize:true});
			}
			else{
				alert(NON_SITE_SELECTED);
			}
		}
		else if(act=='delete_list'){
			arr=checkbox.split(",");
			delDomen(arr);
		}
		else{
			actionList(""+act+"",""+checkbox+"");
		}
	}
	else{
		$.post("index.php",{act:"move_list",new_group:""+act+"",checkbox:""+checkbox+""},function(data){
			Refresh(['top']);Construct();
		})
	}
}




function Cancel(id){
	$('#'+id+'').fadeOut(300,function(){$('#overlay').fadeOut('slow')})
}

function is_array(input){
	return typeof(input)=='object'&&(input instanceof Array)
}

function trim(str,chars){
	return ltrim(rtrim(str,chars),chars)
}

function ltrim(str,chars){
	chars=chars||"\\s";return str.replace(new RegExp("^["+chars+"]+","g"),"")
}

function rtrim(str,chars){
	chars=chars||"\\s";return str.replace(new RegExp("["+chars+"]+$","g"),"")
}

function Refresh(part){
var new_top = getClientCenterY()-25;
var new_left = getClientCenterX()-25;
$('#loading').css({'top':new_top+'px','left':new_left +'px','visibility':'visible','z-index':'2000'});
$("#info").html(LOADING);
if(is_array(part)){for(var i=0;i<part.length;i++){doRefresh(part[i])}}else{doRefresh(part)}$("body").ajaxStop(function(){$("#loading").css("visibility","hidden");$("#info").html("")})}

function doRefresh(part){
	switch(part){
		case"top":
			$.post("index.php",{act:"top"},function(data){$("#topContent").html(data)});
		break;
		case"bottom":
			$.post("index.php",{act:"bottom"},function(data){$("#bottomContent").html(data)});
		break;
		case"tablea":
			$.post("index.php",{act:"tablea"},function(data){$("#tablea").parent().html(data)});
		break;
		default:
			$.post("index.php",{act:"cancel"},function(data){$("#cont").html(data)});
		break
	}
}

function addDomenList(){
	var domenList=document.getElementById("domenList").value;
	var d1=document.getElementById("d1").value;
	var addGroup=document.getElementById("addGroup").value;
	var addOnly=document.getElementById("addOnly").checked;
	if (addOnly==true) {
		var new_top = getClientCenterY()-25;
		var new_left = getClientCenterX()-25;
		$('#loading').css({'top':new_top+'px','left':new_left +'px','visibility':'visible','z-index':'2000'});
		$("#info").html(ADD);
		$.post("index.php",{act:"add_domen_list",domenList:""+domenList+"",d1:""+d1+"",addGroup:""+addGroup+"",addOnly:""+addOnly+""},function(data){
			if(trim(data).length>0){
				$.modal(data, {autoResize:true});
			}
			else{
				Refresh(['top']);Construct();
			}
		});
		$("#loading").css("visibility","hidden");
		$("#info").html("")
	}else {
		if (addGroup) {
			$.post("index.php",{act:"add_group",groupName:""+addGroup+""},function(data){
				//alert(data);
				var id = data;
				var new_top = getClientCenterY()-11;
				var new_left = getClientCenterX()-125;
				$("#loading").css({'top':new_top+'px','left':new_left +'px','visibility':'visible','z-index':'2000'}).draggable({ opacity: 0.7 });
				$("#loader").css({'width':'250px','height':'22px','border':'1px solid #ededed'});
				$("#count").css('width','0%');
				$("#info").css("width","20px").html("0%");
				addDomenListBar(domenList,id,0);
			})
		}else {
			var new_top = getClientCenterY()-11;
			var new_left = getClientCenterX()-125;
			$("#loading").css({'top':new_top+'px','left':new_left +'px','visibility':'visible','z-index':'2000'}).draggable({ opacity: 0.7 });
			$("#loader").css({'width':'250px','height':'22px','border':'1px solid #ededed'});
			$("#count").css('width','0%');
			$("#info").css("width","20px").html("0%");
			addDomenListBar(domenList,d1,0);
			$('#addDomenList').fadeOut('fast');
			document.getElementById("domenList").value="";
		}
	}
};

function addDomenListBar(domenList,group,indx){
	var arrx=domenList.split("\n");
	if (arrx.length>indx) 
	{     
		var id=arrx[indx];
		$.post("index.php",{act:"add_domen_list_bar",domen:""+id+"",group:""+group+"",addOnly:"false"},function(data){
			$("#count").html(data);
			var next_id=indx+1;
			var value = Math.floor(next_id*100/arrx.length);
			ProgressBar (value);
			if (arrx.length>next_id)
			{
				addDomenListBar(domenList,group,next_id);
			}
			else {
				$("#count").html("");
				Refresh(['top']);
				Construct();
			}
		});   
		return true;
	}
};


function delApprove(id){
	show_error('Вы действительно хотите удалить домен?<br/><table align="center" class="button"><tr><td><div class="reg" onclick="delDomen('+id+');"></div></td><td><div class="break" onclick="Cancel(\'error\');"></div></td></tr></table>')
}

function delDomen(id){
	var new_top = getClientCenterY()-25;
	var new_left = getClientCenterX()-25;
	if (confirm(ARE_YOU_SURE)) {
		$('#loading').css({'top':new_top+'px','left':new_left +'px','visibility':'visible','z-index':'2000'});
		$("#info").html(DELETING);
		$.post("index.php",{act:"del_domen",id:""+id+""},function(data){
			$("#loading").css("visibility","hidden");
			$("#info").html("")
			Refresh(['top']);
			Construct();
		});
	}
}

function show_form(){
	var new_top = getClientCenterY()-25;
	var new_left = getClientCenterX()-25;
	$('#loading').css({'top':new_top+'px','left':new_left +'px','visibility':'visible','z-index':'2000'});
	$("#info").html(LOADING);
	$.post("index.php",{act:"show_form_add"},function(data){
		$.modal(data, {autoResize:true});
		$("#loading").css("visibility","hidden");
		$("#info").html("");
	});
}


function show_groups(){
	var new_top = getClientCenterY()-25;
	var new_left = getClientCenterX()-25;
	$('#loading').css({'top':new_top+'px','left':new_left +'px','visibility':'visible','z-index':'2000'});
	$("#info").html(LOADING);
	$.post("index.php",{act:"show_groups"},function(data){
		$.modal(data, {autoResize:true});
		$("#loading").css("visibility","hidden");
		$("#info").html("");
	});
}

function show_usermanager(){
	var new_top = getClientCenterY()-25;
	var new_left = getClientCenterX()-25;
	$('#loading').css({'top':new_top+'px','left':new_left +'px','visibility':'visible','z-index':'2000'});
	$("#info").html(LOADING);
	$.post("index.php",{act:"usermanager"},function(data){
		$.modal(data, {autoResize:true});
		$("#loading").css("visibility","hidden");
		$("#info").html("");
	})
}

function addNewUser(){
	var user=document.getElementById("username").value;
	var pass=document.getElementById("userpass").value;
	var type=document.getElementById("usertype").value;
	var array_usergroup=document.getElementById("usergroup");
	var usergroup = getSelectedIndexes(array_usergroup);
	var array_usermod=document.getElementById("usermod");
	var usermod = getSelectedIndexes(array_usermod);
	if (trim(user).length<=0 || trim(pass).length<=0) {alert('Не указан логин или пароль')}
	else {
		if (usermod.length<=0 || usergroup.length<=0) {alert("Не выбрана группа или модуль!")}
		else {
			var new_top = getClientCenterY()-25;
			var new_left = getClientCenterX()-25;
			$('#loading').css({'top':new_top+'px','left':new_left +'px','visibility':'visible','z-index':'2000'});
			$("#info").html(SAVE);
			$.post("index.php",{act:"add_new_user",user:""+user+"",pass:""+pass+"",type:""+type+"",usergroup:""+usergroup+"",usermod:""+usermod+""},function(data){
			if (trim(data).length>0) {
				$("#simplemodal-data").html(data);
			}
				else alert ('Пользователь с таким именем уже существует');
			});
		}
	}
}

function SaveUser(id) {
	var type=document.getElementById("usertype_"+id+"").value;
	var array_mod=document.getElementById("accessmodule_"+id+"");
	var array_group=document.getElementById("accessgroup_"+id+"");
	var mod = getSelectedIndexes(array_mod);
	var group = getSelectedIndexes(array_group);
	if (mod.length<=0 || group.length<=0) {alert("Не выбрана группа или модуль!")}
	else {
		var new_top = getClientCenterY()-25;
		var new_left = getClientCenterX()-25;
		$('#loading').css({'top':new_top+'px','left':new_left +'px','visibility':'visible','z-index':'2000'});
		$("#info").html(SAVE);
		$.post("index.php",{act:"save_user",id:""+id+"",type:""+type+"",mod:""+mod+"",group:""+group+""},function(data){
			alert("Настройки вступят в силу при следующей авторизации пользователя!");
		});
	}
}

function delUser(id) {
	if (confirm(ARE_YOU_SURE)) {
		var new_top = getClientCenterY()-25;
		var new_left = getClientCenterX()-25;
		$('#loading').css({'top':new_top+'px','left':new_left +'px','visibility':'visible','z-index':'2000'});
		$("#info").html(DELETING);
		$.post("index.php",{act:"del_user",id:""+id+""},function(data){
			$("#simplemodal-data").html(data);
		});
	}
}


function getSelectedIndexes (oListbox)
{
  var arrIndexes = new Array;
  for (var i=0; i < oListbox.options.length; i++)
  {
      if (oListbox.options[i].selected) arrIndexes.push(oListbox.options[i].value);
  }
  return arrIndexes;
};

function group(){
	var new_top = getClientCenterY()-25;
	var new_left = getClientCenterX()-25;
	$('#loading').css({'top':new_top+'px','left':new_left +'px','visibility':'visible','z-index':'2000'});
	$("#info").html(SAVE);
	var checkbox="";
	var check="";
	var rename="";
	$(".g").each(function(){var id=$(this).attr("i");
	if((this).checked){checkbox+=id+","}check+=id+",";
	rename+=$('#gn_'+id+'').val()+","});
	$.post("index.php",{act:"rename_group",checkbox:""+check+"",rename:""+rename+""});
	$.post("index.php",{act:"change_group",group:""+checkbox.slice(0,(checkbox.length-1))+""},function(data){
		Refresh(['top']);
		Construct();
	})
}

function delGroup(id){
	var new_top = getClientCenterY()-25;
	var new_left = getClientCenterX()-25;
	$('#loading').css({'top':new_top+'px','left':new_left +'px','visibility':'visible','z-index':'2000'});
	$("#info").html(DELETING);
	$.post("index.php",{act:"del_group",id:""+id+""},function(data){
		Refresh(['top']);
		$("#simplemodal-data").html(data);
		$("#loading").css("visibility","hidden");
		$("#info").html("");
	});
}

function AddNewGroup(type) {
	addGroup=document.getElementById('addGroupName').value;
	if(addGroup!="") {
		var new_top = getClientCenterY()-25;
		var new_left = getClientCenterX()-25;
		$('#loading').css({'top':new_top+'px','left':new_left +'px','visibility':'visible','z-index':'2000'});
		$("#info").html(SAVE);
		$.post("index.php",{act:"add_group",groupName:""+addGroup+"",result:""+type+""},function(data){
			if(trim(data).length>0) {
				$("#simplemodal-data").html(data);
				$("#loading").css("visibility","hidden");
				$("#info").html("");
				Refresh(['top']);
			}else{
				alert("Такая группа уже есть");
			}
		});
	}else alert('Не указано название группы');
}

function delModule(module){
	if (confirm("Вы уверены, что хотите удалить модуль "+module+"?")) {
		var new_top = getClientCenterY()-25;
		var new_left = getClientCenterX()-25;
		$('#loading').css({'top':new_top+'px','left':new_left +'px','visibility':'visible','z-index':'2000'});
		$("#info").html(DELETING);
		$.post("index.php",{act:"del_module",module:""+module+""},function(data){
			$("#simplemodal-data").html(data);
			Refresh(['top']);
			$("#loading").css("visibility","hidden");
			$("#info").html("")
		});
	}
}

function changeGroup(){
	var new_top = getClientCenterY()-25;
	var new_left = getClientCenterX()-25;
	$('#loading').css({'top':new_top+'px','left':new_left +'px','visibility':'visible','z-index':'2000'});
	$("#info").html(CHANGE_GROUP);
	$.post("index.php",{act:"change_group",group:""+$("#group1").val()+""},function(){
		Refresh(['top']);
		Construct();
	})
}

function show_config(){
	var new_top = getClientCenterY()-25;
	var new_left = getClientCenterX()-25;
	$('#loading').css({'top':new_top+'px','left':new_left +'px','visibility':'visible','z-index':'2000'});
	$("#info").html(LOADING);
	$.post("index.php",{act:"config_module"},function(data){
		$.modal(data, {autoResize:true});
		$("#loading").css("visibility","hidden");
		$("#info").html("");
	});
}

function saveConfig(){
	var new_top = getClientCenterY()-25;
	var new_left = getClientCenterX()-25;
	$('#loading').css({'top':new_top+'px','left':new_left +'px','visibility':'visible','z-index':'2000'});
	$("#info").html(SAVE);
	var view_icons=document.getElementById("view_icons").checked;
	var view_group=document.getElementById("view_group").checked;
	var skin=$("#skin option:selected").val();
	var lang=$("#lang option:selected").val();
	var view_footer=document.getElementById("view_footer").checked;
	var view_scrolling=document.getElementById("view_scrolling").checked;
	var pass=document.getElementById("pass").value;
	var pass_confirm=document.getElementById("pass_confirm").value;
	if(pass!=""){if(trim(pass)!=trim(pass_confirm)){pass="";alert("Вы неправильно указали подтверждение пароля");}}
	$.post("index.php",{act:"save_config",view_group:""+view_group+"",view_icons:""+view_icons+"",skin:""+skin+"",lang:""+lang+"",view_footer:""+view_footer+"",view_scrolling:""+view_scrolling+"",pass:""+pass+""},function(data){
		$("body").html(data);
		$("#loading").css("visibility","hidden");
		$("#info").html("")
	});
}

function addmodule() {
	var add_module=document.getElementById("addModule").value;
	if(add_module!=""){
		var myRe = /.xml/ig;
		var myArray = myRe.exec(add_module);
		if(myArray=='.xml') {
			$("#addModuleFrm").submit();
			$.post("index.php",{act:"config_module"},function(data){
				//alert(data);
				
				Refresh(['top']);
				$("#simplemodal-data").html(data);
			});
		}else alert("Установочный файл должен иметь расширение .xml");
	}
	else alert("Не указан файл");
}

function show_error(str){
	var new_top = getClientCenterY()-50;
	var new_left = getClientCenterX()-100;
	$('#error').css({'top':new_top+'px','left':new_left +'px','display':'block','z-index':'100'});
	$("#error_cont").html(str);
	$('#error').draggable({ opacity: 0.7 });
	close();
}

function logoutUser(){
	var new_top = getClientCenterY()-25;
	var new_left = getClientCenterX()-25;
	$('#loading').css({'top':new_top+'px','left':new_left +'px','visibility':'visible','z-index':'2000'});
	$("#info").html(EXIT);
	$.post("index.php",{act:"logout_user",user:"quit"},function(data){$("#cont").html(data)});
}


function changeModule(){
	var new_top = getClientCenterY()-25;
	var new_left = getClientCenterX()-25;
	$('#loading').css({'top':new_top+'px','left':new_left +'px','visibility':'visible','z-index':'2000'});
	$("#info").html(LOAD_MODULE);
	var module=$("#module").val();
	$.post("index.php",{act:"save_config",module:""+module+""},function(data){
		$("#cont").html(data);
		$("#loading").css("visibility","hidden");
		$("#info").html("")
	});
}

function rebuildChildRow(){
	$(".child").each(function(){
		var id=$(this).attr("parId");
		$("#cont_"+id).after($(this));
	})
}

function checkedRow(id){
	if(typeof id=="undefined"){var sel=".parent"}
	else{var sel="#cont_"+id}
	$(sel+">td:not(.non_checked)").click(function(e){
		var elm=e.target||event.srcElement;
		if(elm.tagName.toLowerCase()=="input"){
			$(this).parent().toggleClass("checked_row");return
		}
		var $flag=$("input",$(this));
		if($flag.html()==null){
			if($("select",$(this)).html()==null){$flag=$("input",$(this).parent())}else{return}
		}var checked=$flag.attr("checked");
		if(checked==false){
			$flag.attr("checked","checked");
			$(this).parent().toggleClass("checked_row")
		}else{
			$flag.removeAttr("checked");
			$(this).parent().toggleClass("checked_row");
		}
})}

function arrow(){
	/* if(typeof id=="undefined"){var sel=".parent"}
	else{
		var sel="#cont_"+id;
		var obj=$(sel+">td>div.arrow");
		obj.parent().parent().removeClass("nodrag");
		obj.removeClass("up");
		obj.parent().parent().next("tr").hide();
	}
	$(sel+">td>div.arrow").click(function(){
		$(this).parent().parent().toggleClass("nodrag");
		$(this).toggleClass("up");
		$(this).parent().parent().next("tr").toggle();
		if(window.childContent){
			var cont_id=$(this).parent().parent().attr("id");
			var id=cont_id.substring(5,cont_id.length);
			childContent(id);
		}
	}) */
	
		/* 	row += '<tr class="body child" parId="'+val['id']+'"><td align="center" valign="top" id="sub_id_'+val['id']+'"></td><td width="10" valign="top" align="center" id="sub_num_'+val['id']+'"></td><td class="row" valign="top"  width="10" id="sub_arrow_'+val['id']+'"></td>';
		if (val['icons'] != 0) row += '<td class="icons" valign="top" id="icons_'+val['id']+'"></td>';
		row += '<td valign="top" valign="top"  nowrap="nowrap" class="url" id="sub_url_'+val['id']+'"></td>';
		if (data.table['group'] != 0) {row += '<td valign="top" align="center" class="group" id="sub_group_'+val['id']+'"></td>';
		//else row += '<td valign="top" align="center" class="group" id="sub_group_'+val['id']+'"></td>';
		}
		//row += '<td valign="top" align="center" class="group" id="sub_group_'+val['id']+'"></td>';
		if (val['child'] != 0) row += val['child'];
		row += '<td valign="top" align="center" style="padding-right:15px;" width="64" id="sub_action_'+val['id']+'"></td></tr>'; */


}

/* function close() {
$(".box_top_right").css("z-index","200");
$(".box_top_right").click(function(){$(this).parent().parent().parent().parent().fadeOut("fast")});
} */

function tablea(rank){
	$("#tablea tr:not(.child, .exchange, .dnd, .act_but, .fixed)").hover(function(){
		var nodrag=$(this).hasClass("nodrag");
		if(nodrag==false){
			$(this.cells[1]).addClass('showDragHandle');
		}
	},function(){
		$(this.cells[1]).removeClass('showDragHandle');
	});
	$("#tablea").tableDnD({
		onDrop:function(table,row){
			var new_top = getClientCenterY()-25;
			var new_left = getClientCenterX()-25;
			$('#loading').css({'top':new_top+'px','left':new_left +'px','visibility':'visible','z-index':'2000'});
			$("#info").html(MOVE);
			var rows=table.tBodies[0].rows;
			newOrder="";
			for(var i=0;i<rows.length;i++){
				var id=rows[i].id.substring(5,rows[i].id.length);
				if(id.length>0) newOrder+=id+",";
			}
			newOrder=newOrder.slice(0,(newOrder.length-1));
			rebuildChildRow();
			$.post("index.php",{act:"save_order",rank:""+rank+"",order:""+newOrder+""});
			$("body").ajaxStop(function(){$("#loading").css("visibility","hidden");
			$("#info").html("")})
		},
		dragHandle:"dragHandle",
		onDragClass:"dragRow"
	});
	
	$("#tablea").tablesorter({widgets: ['zebra']});
	$("#tablea").bind("sortStart",function(){
		var new_top = getClientCenterY()-25;
		var new_left = getClientCenterX()-25;
		$('#loading').css({'top':new_top+'px','left':new_left +'px','visibility':'visible','z-index':'2000'});
		$("#info").html(SORTING);
	}).bind("sortEnd",function(){rebuildChildRow();
	
	$("#loading").css("visibility","hidden");
	$("#info").html("");});
	$("#checkAll").click(function(){
		var checked_status=this.checked;
		$(".parent input:checkbox").each(function(){
			this.checked=checked_status;
			switch(checked_status){
				case true:
					$(this).parent().parent().addClass("checked_row");
				break;
				case false:
					$(this).parent().parent().removeClass("checked_row");
				break
			}
		})
	});
	$('.arrow').click(function () {
		var rank = $(this).attr('value');

		if ( $(this).hasClass('up') )
		{
			$(this).removeClass('up');
			$("tr#cont_"+rank+"").removeClass('nodrag');
			$('.child_'+rank).remove();
		}
		else
		{
			$(this).addClass('up');
			var tr = '<tr parId="'+rank+'" class="child_'+rank+'">';
			var n = 0;
			$("tr#cont_"+rank+" > td").each(function(){
				var id = $(this).attr('id');
				var h = id.replace(rank,"");
				var h = h.replace("_","");
				tr+='<td id="sub_'+h+'_'+rank+'" valign="top"></td>';
				n++;
			});
			tr += '</tr>';
			$("tr#cont_"+rank+"").addClass('nodrag');
			$("tr#cont_"+rank+"").after(tr);
			if(window.childContent){
				childContent(rank);
			}
		}
	} );
	checkedRow();
}


