function Selects(selectPage, selectGroup, labels) { //, selectBanner) {
	
	this.selectPage = selectPage;
	this.selectGroup = selectGroup;
	//this.selectBanner = selectBanner;
	
	this.Pages = new Array();
	this.Groups = new Array();
	if (labels == null || labels.length!=2) {
		this.mLabel = 'Wybierz';
		this.Label = 'Wybierz';
	}
	else {
		this.mLabel = labels[0];
		this.label = labels[1];
	}
	
	//this.Banners = new Array();
}

Selects.prototype.search = function(table, elem) {
	var len = table.length;
	var result = new Array();
	for (i=0; i < len; i++) {
		if (table[i]!= null && table[i][0] == elem) result[result.length] = [table[i][2], table[i][1]];
	}
	return result;
}

Selects.prototype.in_array=function(table, index) {
	var len = table.length;
	//alert('in_array '+len+' index: '+index);
	if (index > len) return false;
	if (table[index] == null) return false;
	//alert('nie ma');
	return true;
}

Selects.prototype.addMain = function(page_id, page) {
	this.Pages[this.Pages.length] = new Array(page_id,page);
}

Selects.prototype.add = function(group_id, page_id, group) {
	this.Groups[this.Groups.length] = [page_id, group,group_id];
}

Selects.prototype.init = function(){
	//if (this.phones == null) return false;

	var len  = this.Pages.length;
	//alert(len);
	this.selectPage.options[0] = new Option(this.mLabel, 0);
	var j = 1;
	
	for (i=0; i< len; i++) {
		if (this.Pages[i] != null) {
			this.selectPage.options[j++] = new Option(this.Pages[i][1], this.Pages[i][0]);
		}
	}
	this.chooseGroup();
	//this.selectBanner.style.visibility='hidden';
}

Selects.prototype.chooseGroup = function(){
	
	//if (this.phones == null) return false;
	var val = this.selectPage.value;
	if (val < 0) return false;
	//alert(val);
	this.selectGroup.options.length =0;
	
	var res = this.search(this.Groups, val);
	
	this.selectGroup.options[0] = new Option(this.label, 0);
	
	for (i=0; i<res.length; i++) {
		this.selectGroup.options[i+1] = new Option(res[i][1], res[i][0]);
	}
	
	this.selectGroup.selectedIndex = 0;
	/*if (val > 0) ShowHide('GroupTable', false);
	else ShowHide('GroupTable', true); */
	
	//this.chooseBanner();
	
}
/*
Selects.prototype.chooseBanner = function(){
	
	var val = this.selectGroup.value;
	if (val < 0) return false;
	
	this.selectBanner.options.length =0;
	
	var res = this.search(this.Banners, val);
	
	this.selectBanner.options[0] = new Option('Wszystkie', 0);
	
	for (i=0; i<res.length; i++) {
		this.selectBanner.options[i+1] = new Option(res[i][1], res[i][0]);
	}
	
	this.selectBanner.selectedIndex = 0;
	if (val > 0) ShowHide('BannerTable', false);
	else ShowHide('BannerTable', true);
	
}
*/
Selects.prototype.setVal=function(type, val) {
	var s = eval('this.select'+type);
	var len = s.options.length;
	for (i=0; i< len; i++) {
		if (s.options[i].value == val) {
			s.selectedIndex=i;
			break;
		}
	}
}

Selects.prototype.check=function() {
	if (this.selectGroup.value == 0 || this.selectPage.value == 0) {
		alert('Musisz wybrać kategorię');
		return false;
	}
	return true;
}

function ShowHide(blockid, hide) {
	var objekt;
	if (document.all) objekt=document.all[blockid];
	else objekt = document.getElementById(blockid);
	
	if (objekt == null) {
		alert('Nie odnaleziono obiektu o id '+blockid);
		return false;
		}
	
	if (hide) {
		objekt.style.visibility='hidden';
	}
	else objekt.style.visibility='visible';
	return true;
}






