
var AttributesPopup = {
	objTabList : new AttributesPopupTabList(),
	blnVisible : false,
	objCurrentTab : null,
	intControls : 0,
	intTabs : 0,
	strUrlExtraParams : '',
	strUrl : '',
	strCurrentGroupId : '0',
	
	startTab : function (){
		this.objCurrentTab = new AttributesPopupTab();
	},
	
	endTab : function (){
		this.objTabList.addTab(this.objCurrentTab);
	},
	
	addControl : function (strControlType, mixInitialState, strHtmlId, strUrlPart, strLabel, intAttributeId, intAttributeValue, intParentId, intParentValue){
		var objControl = new AttributesControl(strControlType, this.intControls++, mixInitialState, strHtmlId, strUrlPart, strLabel, intAttributeId, intAttributeValue, intParentId, intParentValue);
		this.objCurrentTab.addControl(objControl);
	},
	
	getUrlParam : function (){
		return this.objTabList.getUrlParam();
	},
	
	resetState : function (){
		return this.objTabList.resetState();
	},
	
	updateControls : function (){
		return this.objTabList.updateControls();
	},
	
	setTabName : function (strName){
		this.objCurrentTab.setDisplayName(strName);
		
	},
	
	setTabGroupId : function (strGroupId){
//		this.objCurrentTab.setGroupId(strGroupId);
		this.objCurrentTab.setGroupId(this.intTabs++);
	},
	
	setTabGroupParent : function (intParentId, intParentValue){
		this.objCurrentTab.setParent(intParentId, intParentValue);
	},
	
	displayMenu : function (){
		document.getElementById('ap_right_content').innerHTML = '<p>Alte optiuni:</p><ul class="popup_list">'+ this.objTabList.getButtons(this.strCurrentGroupId) +'</ul>';
	},
	
	displayTab : function (strGroupId){
		this.strCurrentGroupId = strGroupId;
		this.displayMenu();
		return this.objTabList.displayTab(strGroupId);
	},
	
	getState : function (intControlId){
		return this.objTabList.getState(intControlId);
	},
	
	getAttributeId : function (intControlId){
		return this.objTabList.getAttributeId(intControlId);
	}, 
	
	getParent : function (intControlId){
		return this.objTabList.getParent(intControlId);
	},
	
	getValue : function (intControlId){
		return this.objTabList.getValue(intControlId);
	},
	
	changeState : function (intControlId, mixNewState){
		// TODO: parent refresh
		var intAttributeId = this.getAttributeId(intControlId);
		var intValue = this.getValue(intControlId);
		if (mixNewState){
			this.objTabList.showDependent(intAttributeId, intValue);
		} else {
			this.objTabList.hideDependent(intAttributeId, intValue);
		}
		this.displayMenu();
		return this.objTabList.changeState(intControlId, mixNewState);
	},
	
	updateState : function (intAttributeId, intAttributeValue){
		return this.objTabList.updateState(intAttributeId, intAttributeValue);
	},
	
	close : function (){
		this.resetState();
		this.updateControls();
		document.getElementById('box_popup_fitru').style.display = 'none';
	},
	
	getIEVersion : function (){
		var ua = navigator.userAgent;
	    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
	    var rv = -1;
	    if (re.exec(ua) != null){
	    	rv = parseFloat( RegExp.$1 );
	    }
	    return rv;
	},
	
	show : function (strGroupId){
		this.displayTab(strGroupId);
		var objBox = document.getElementById('box_popup_fitru');
		objBox.style.display = 'block';
//		objBox.style.document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight)/2 + top1  = document.documentElement.scrollTop  ? document.documentElement.scrollTop  : document.body.scrollTop )) + 'px' );
			
	   var intIEVersion = this.getIEVersion();
	    	if (intIEVersion < 8 && intIEVersion > -1){
	    		var intCorrection = 0;
	    		if (intIEVersion < 7){
	    			if (document.documentElement.scrollTop < objBox.clientHeight){
	    				intCorrection = (objBox.clientHeight - document.documentElement.scrollTop)/2-20;
	    			}
	    		}
	    		objBox.style.top = (document.documentElement.scrollTop  ? document.documentElement.scrollTop  : document.body.scrollTop) + intCorrection + 'px';
	    	} else {
	    		// objBox.style.top = (document.documentElement.scrollTop  ? document.documentElement.scrollTop  : document.body.scrollTop) - objBox.clientHeight + 'px';
	    	}
	   
	},
	
	addUrlExtraParams : function (strParams){
		this.strUrlExtraParams += strParams;
	},
	
	setUrl : function (strUrl){
		this.strUrl = strUrl;
	}, 
	
	getUrl : function (){
		return this.strUrl + this.strUrlExtraParams  + this.getUrlParam() + '&atf=1';
	},
	
	submit : function (){
		document.location = this.getUrl();
	},
	
	hideDependent : function (intAttributeId, intAttributeValue){
		this.objTabList.hideDependent(intAttributeId, intAttributeValue);
	},
	
	hideDependentByAttributeId : function (intAttributeId){
		this.objTabList.hideDependentByAttributeId(intAttributeId);
	},
	
	hideDependentFilters : function (intAttributeId, intAttributeValue){
		this.objTabList.hideDependentFilters(intAttributeId, intAttributeValue);
	},
	
	showDependent : function (intAttributeId, intAttributeValue){
		this.objTabList.showDependent(intAttributeId, intAttributeValue);
	},
	
	submitFilter : function (intAttributeId, intAttributeValue, blnEnabled){
		if (!blnEnabled){
			this.hideDependentFilters(intAttributeId, intAttributeValue);
		}
		document.getElementById('at_form').submit();
	},
	
	applyFilter : function (intAttributeId, intAttributeValue, blnEnabled){
		var objElem = document.getElementById('cb_at_' + intAttributeId + '_' + intAttributeValue);
		objElem.checked = blnEnabled;
		if (!blnEnabled){
			this.hideDependentFilters(intAttributeId, intAttributeValue);
		}
		document.getElementById('at_form').submit();
	},
	

	applySimpleFilter : function (intAttributeId,  blnEnabled){
		var objElem = document.getElementById('cb_at_' + intAttributeId);
		objElem.checked = blnEnabled;
		if (!blnEnabled){
			this.hideDependentFilters(intAttributeId, 1);
		}
		document.getElementById('at_form').submit();
	},
	
	
	updateFilters : function (){
		this.objTabList.updateFilters();
	},
	
	build: function (){
		this.objTabList.build();
		this.updateFilters();
		var objPopup = document.getElementById('box_popup_fitru');
		if (typeof document.body.style.maxHeight == "undefined") {
			
		} else {
			if (objPopup != null){
				objPopup.setAttribute('style', 'position: fixed; top: 50%; left: 50%;  margin: -225px 0 0 -322px;');
			}
		}
	},
	
	dump : function (){
		return '<ul><li>AttributesPopup<ul>'
		+'<li>blnVisible = '+(this.blnVisible?'true':'false')+'</li>'
		+'<li>objTabList = '+this.objTabList.dump()+'</li>'
		+'</ul></li></ul>';
	}
	
};


//alert(AttributesPopup.dump());



