_standartAdmin = Class.create();
_standartAdmin.prototype = {
	initialize: function(){
		this.img_dir = '';		
		this.soData = new Object();
	},
	
	initData: function(dt){
		this.img_dir = dt;
		
		var so = $('orientation').value;

			
		if(so != ''){
			this.saveInitData(so, 'so');
		}
		document.getElementsByClassName('childs').each(function(elm){
			elm.hide();
		}.bind(this));
		
		this.sectorswitch('1', 'so-');
		
		
	},
	
	saveInitData: function(dt, prefix){
		dt.split(',').each(function(row,idx){
			this[prefix + 'Data'][row] = row;
			$('cb'+prefix+'-' + row).checked = true;
		}.bind(this));
	},
	
	sectorswitch: function(id, pref){
		$('childs' + pref + id).toggle();
		var imgid = 'img' + pref + id;
		
		if($(imgid).hasClassName('plus')){
			$(imgid).removeClassName('plus');
			$(imgid).addClassName('minus');
			if($(imgid).hasClassName('bottom')){
				$(imgid).src = this.img_dir + "minusbottom.gif";
			}else{
				$(imgid).src = this.img_dir + "minus.gif";
			}
		}else{
			$(imgid).removeClassName('minus');
			$(imgid).addClassName('plus');
			if($(imgid).hasClassName('bottom')){
				$(imgid).src = this.img_dir + "plusbottom.gif";
			}else{
				$(imgid).src = this.img_dir + "plus.gif";
			}
		}
	},
	
	parentCheck: function(id, pref){
		this.setChilds(id, $('cb' + pref + id).checked, pref);
		this.setData(id, pref);
	},
	
	setChilds: function(id, stat, pref){
		document.getElementsByClassName('cbpar' + pref + id).each(function(elm){
			elm.checked = stat;
			this.setData(elm.id.split('-')[1], pref);
			if(elm.hasClassName('parent')){
				this.setChilds(elm.id.split('-')[1], stat, pref);
			}
		}.bind(this));
	},
	
	setData: function(id, pref){
		this[pref.split('-')[0] + 'Data'][id] = $('cb' + pref + id).checked?id:'';
	},
	
	sectorCheck: function(id, pref){
		this.setData(id, pref);
	},
	
	parseData: function(){		
		$('orientation').value = this.getSubmitData('so');			
	},
	
	getSubmitData: function(prefix){
		var dt='';
		for(var i in this[prefix + 'Data']){
			if(this[prefix + 'Data'][i] != '')
				dt += this[prefix + 'Data'][i] + ',';
		}
		if(dt != ''){
			dt = dt.substr(0,dt.length-1);
		}
		return dt;
	},
	
	submitData: function(){
		this.parseData();
	}
};

standartAdminJS = new _standartAdmin();