    var debug=false;
	var MAXNUMCELLS=1000;
    // convert all characters to lowercase to simplify testing 
    var agt=navigator.userAgent.toLowerCase(); 

    // *** BROWSER VERSION *** 
    // Note: On IE5, these return 4, so use is_ie5up to detect IE5. 
    var is_major = parseInt(navigator.appVersion); 
    var is_minor = parseFloat(navigator.appVersion); 

    // Note: Opera and WebTV spoof Navigator.  We do strict client detection. 
    // If you want to allow spoofing, take out the tests for opera and webtv. 
 var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) 
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) 
                && (agt.indexOf('webtv')==-1)); 
    var is_nav2 = (is_nav && (is_major == 2)); 
    var is_nav3 = (is_nav && (is_major == 3)); 
    var is_nav4 = (is_nav && (is_major == 4)); 
    var is_nav4up = (is_nav && (is_major >= 4)); 

function MM_findObj2(n, d) { //v3.0
	var p,i,x;  
	if(!d) 
		d=document; 
	if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; 
		n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all) 
		x=d.all[n];
	for (var i=0;!x&&i<d.forms.length;i++)
		x=d.forms[i][n];
	for(var i=0;!x&&d.layers&&i<d.layers.length;i++)
		x=MM_findObj(n,d.layers[i].document);
	return x;
}

function MM_findObj(n, d) { //v3.0
	var x=null;
	if (n!=null){
		if(parent.frames.length>0) {
			for (var i=0;i<parent.frames.length;i++) {
				d=parent.frames[i].document;
				x=MM_findObj2(n, d)
				if (x!=null)
					break;
			}
		} else {
			x=MM_findObj2(n, d)
		}
	}
	return x;
	
}

//Generic removeElementArray;
function removeElementArray(element,vArray,numberElement) {
	var bValue=false;
	var pArray = new Array(); //private Array to remove the element.
	var j = 0;
	for (var i=0;i<=numberElement;i++) { //loop to search the element for removing
		if (vArray[i] == element) {		 //when the element is found it is removed
			bValue = true;
			continue;
		}
		pArray[j]=vArray[i];
		j++
	}
	numberElement = j;					//resize the number of elements
	vArray=pArray;						//Set Array with the values ofthe private Array
	return (bValue)
}

	
/* All the objects using the Menu toolkit should implement the follow Interface:
(JavaScript have not specific semantic to express the Interfaces)

Intreface List()
	Properties
		*All the properties are Privates*
		list - Array of elements in the list
		numberElements - integer for counting the number of elements in the list
		static defaultLabel - Default label for the list
	Methods
		add - To add a new element in the list
		getList - To get the list 
		setList - To set the list 
		setDefaultLabel - To change the value of the default label
*/
		
function ListGen(label) {		//new General Object to Implement the basic Interface List()
	this.label=label;			//property to set the label for the instruction in the control used in the Menu toolkit
	this.list=new Array();		//*This object implement the aggregateList extended the Interface
	this.numberElements =0;		//list is an Array with label and value property
}
new ListGen();
ListGen.prototype.defaultLabel="";
ListGen.prototype.add=listGenAdd;
ListGen.prototype.getList=listGenGetList;
ListGen.prototype.getFieldDB=listGenGetFieldDB;
ListGen.prototype.getObjectList=listGenGetObjectList;
ListGen.prototype.setList=listGenSetList;
ListGen.prototype.setLabel=listGenSetLabel;
ListGen.prototype.getObject=listGenGetObject;
ListGen.prototype.setDefaultLabel=listGenSetDefaultLabel;
ListGen.prototype.aggregateList=listGenAggregateList;
ListGen.prototype.insertElement=listGenInsertElement;
ListGen.prototype.removeElement=listGenRemoveElement;
ListGen.prototype.eliminateDuplicates=listGenEliminateDuplicates;
ListGen.prototype.numberOfElements=listGenNumberOfElements;

function listGenAdd(element) {						//add the element to the list and resize the number of elements in the list
	this.list.push(element)
	this.numberElements =this.list.length;
}

function listGenNumberOfElements() {
	return(this.numberElements);
}

function listGenGetList() {						//*Generate a list (Array) with all the elements, including
	var vlist = new Array();						//*a first element to set the message for the control Menu Toolkit
	vlist[0]= new Array();
	vlist[0].label=tabMsg.get("select")+this.label+"--"
	vlist[0].value=""
	for (var i=1;i<=this.numberElements;i++) {
		vlist[i]=this.list[i-1]
	}
	return (vlist)
}

function listGenGetObjectList() {						//*Generate a list (Array) with all the elements, including
	return (this.list)
}

function listGenSetList(list) {					//Set the list
	if (list!=null) {
		this.list=list;
		this.numberElements=this.list.length;
	}
}

function listGenSetDefaultLabel(label) {		//Set default label
	this.defaultLabel=label;
}

function listGenGetFieldDB() {
	if (this.list[0].getFieldDB!=null)
		value=this.list[0].getFieldDB();
	else
		value=false;
	return(value);
}

function listGenSetLabel(label) {		//Set default label
	this.label=label;
	this.defaultLabel=label;
}

function listGenAggregateList(sublist,sort) {		//Generate the union of the list and sublist sorting by label
	var exist = false;								//The exist variable is used to depure repetitive values
	var listLength=this.list.length;
	for (var i=0;i<sublist.length;i++){				//For each element of the sublist search repetead value in list
		for (j=0;j<listLength;j++){
			if (this.list[j].value==sublist.value) { //the value alredy exist in list
				exist= true;
				break;
			}
			exist = false;
		}
		if (!exist)									//if the element not exist in the list it is added to the list
			this.list[listLength++] = sublist[i];
	}
	if (sort)										//if sort is true the list is sorted using the lables of each element in the list
		this.list.sort(sortLabel);
	this.numberElements=this.list.length
}

function listGenEliminateDuplicates() {
	for (var i=0;i<this.list.length;i++) {
		for (var j=i+1;j<this.list.length;j++){
			if ((this.list[i]==this.list[j]||(this.list[i].value==this.list[j].value&&this.list[i].value!=undefined))&&i!=j){
				this.removeElement(j);
			} 
		}
	}
	this.numberElements=this.list.length
}

function listGenToString() {
	var testListGenTemp=this.getObjectList();
	var vlist = new Array();
	for (var i=0;i<testListGenTemp.length;i++) {
		vlist[i]=testListGenTemp[i].label
	}
	return(vlist.toString())
}

function listGenInsertElement(elements,position) {
	var templist = new Array();
	var nelements = this.list.length+elements.length;
	var delta=0;
	if (position<0) position=0;
	for (var k=0;k<elements.length;k++) {
		templist.push(this.list[k+position])
		if (k+position<this.list.length)
			this.list[k+position]=elements[k];
		else {
			this.list.push(elements[k]);
			delta++
		}
	}
	for (var i=position+elements.length;i<this.list.length;i++) {
		templist.push(this.list[i])
		this.list[i]=templist.shift();
	}
	for (var k=0;k<templist.length-delta;k++) {
		this.list.push(templist[k]);
	}
	this.numberElements=nelements;
}

function listGenRemoveElement(index) {
	var lastElement = this.list.pop();
	var length=this.list.length-1;
	for (var i=index;i<length;i++) {
		this.list[i]=this.list[i+1];
	}
	this.list[length]=lastElement;						//Set Array with the values ofthe private Array
}


function listGenGetObject(index) {					//Get the Control associate to the Subregion
	return (this.list[index])
}

function sortLabel(a,b) {
	if (a.label==b.label)
		return(0);
	if (a.label<b.label)
		return(-1);
	if (a.label>b.label)
		return(1);
}

function sortLabelInd(a,b) {
	var cha=new Array();
	var chb=new Array();
	var cha=a.value.split(".");
	var chb=b.value.split(".");
	if (cha.length>chb.length)
		num=chb.length
	else
		num=cha.length
	for (var i=0;i<num;i++) {
		if (i>0){
			cha[i]=cha[i]*1;
			chb[i]=chb[i]*1;
		}
		if (cha[i]==chb[i]) {
			continue
		}
		if (cha[i]<chb[i]) {
			return(-1);
		}
		if (cha[i]>chb[i]) {
			return(1);
		}
	}
	if (cha.length==chb.length) {
		return(0);
	}
	if (cha.length<chb.length) {
		return(-1);
	}
	if (cha.length>chb.length) {
		return(1);
	}
}

function sortValue(a,b) {
	if (a.value==b.value)
		return(0);
	if (a.value<b.value)
		return(-1);
	if (a.value>b.value)
		return(1);
}

/*function sortPos(a,b) {
	if (a.position==b.position)
		return(0);
	if (a.position<b.position)
		return(-1);
	if (a.position>b.position)
		return(1);
}*/

function Control(control) {
	this.control=control;
	this.level=0;
	this.parent=null;
	this.depent=new Array();
	this.depentNumber=0;
}
new Control(null);
Control.prototype.getParent=controlGetParent;
Control.prototype.setParent=controlSetParent;
Control.prototype.getLevel=controlGetLevel;
Control.prototype.setLevel=controlSetLevel;
Control.prototype.addDepent=controlAddDepent;

function controlGetParent() {			//*Implement List.add method
	return(this.parent);
}

function controlSetParent(parent) {			//*Implement List.add method
	this.parent=parent;
}

function controlGetLevel() {			//*Implement List.add method
	return(this.level);
}

function controlSetLevel(level) {			//*Implement List.add method
	this.level=level;
}

function controlAddDepent(depent) {			//*Implement List.add method
	vDepent = new Control(depent);
	vDepent.setParent(this);
	vDepent.setLevel(this.level+1);
	this.depent[depentNumber++]=depent;
}

//new object Subregion Implement Interfase List()
function Subregion(label,code) {
	this.label=label;
	this.value=code;
	this.countries=new Array();
	this.numberCountries=0;
	this.control=new Array();
	this.numberControls=0;
	this.stop=true;
}
new Subregion(null,null);
Subregion.prototype.defaultLabel=tabMsg.get("country");
Subregion.prototype.fieldDB="Pais";
Subregion.prototype.add=subregionAddCountry;
Subregion.prototype.addSubregion=subregionAddSubregion;
Subregion.prototype.getList=subregionGetList;
Subregion.prototype.getObjectList=subregionGetObjectList;
Subregion.prototype.setList=subregionSetList;
Subregion.prototype.getControl=subregionGetControl;
Subregion.prototype.setControl=subregionSetControl;
Subregion.prototype.setDefaultLabel=subregionSetDefaultLabel;
Subregion.prototype.getObject=subregionGetObject;
Subregion.prototype.getFieldDB=subregionGetFieldDB;
Subregion.prototype.getValue=subregionGetValue;
Subregion.prototype.cleanControl=nullP;
Subregion.prototype.numberOfElements=subregionnumberOfElements;

function subregionnumberOfElements() {
	return(this.numberCountries);
}

function subregionGetFieldDB() {
	return(this.fieldDB);
}

function subregionAddCountry(country) {			//*Implement List.add method
	var list = new ListGen();					//*Add a country in the countries list
	list.setList(this.countries);				//*for this subregion
	list.add(country);							//*via delegation to ListGen()
	this.setList(list.list);
}

function subregionAddSubregion(subregion) {		//*Union of two list countries (subregions)
	var list = new ListGen();					//*via delegation to ListGen()
	list.setList(this.countries);
	list.aggregateList(subregion.countries,true);
	this.setList(list.list);
}

function subregionGetList() {					//Implement List.getList using the LisGen.getList
	var list = new ListGen(this.defaultLabel);	//*via delegation to ListGen()
	list.setList(this.countries);
	return (list.getList())
}

function subregionGetObjectList() {					//Implement List.getList using the LisGen.getList
	var list = new ListGen(this.defaultLabel);	//*via delegation to ListGen()
	list.setList(this.countries);
	return (list.getObjectList())
}

function subregionSetList(list) {					//Set the list
	this.countries=list;
	this.numberCountries=list.length;
}

function subregionGetControl(kind) {				//Get the Control
	return(this.control[kind])
}

function subregionSetDefaultLabel(label){		//Implement List.getList using the LisGen.getList
	this.defaultLabel=label;
}

function subregionSetControl(control){		//
	this.control[control.kind]=control;
	this.nuberControls++
}

function subregionGetObject(index) {					//Get the Control associate to the Subregion
	return (this.countries[index])
}

function subregionGetValue(vArray,lArray) {					//Get the Control associate to the Subregion
	var aLength=vArray.length;
	for (var i=0;i<this.numberCountries;i++) {
		vArray[i+aLength]=this.countries[i].value;
		lArray[i+aLength]="* "+this.countries[i].label;
	}
}

//new object Country
function Country(label,value) {
	this.label=label;
	this.value=value
	this.parent=null;
}
new Country(null,null);
Country.prototype.getList=countryGetList;
Country.prototype.getValue=countryGetValue;
Country.prototype.cleanControl=nullP;

function countryGetList() {					//Implement List.getList using the LisGen.getList
	return (this.value)
}

function countryGetValue(vArray,lArray) {					//Get the Control associate to the Subregion
	var aLength=vArray.length;
	vArray[aLength]=this.value;
	lArray[aLength]="* "+this.label;
}


//new object IndicatorGroup Implement Interfase List()
function IndicatorGroup(label,code) {
	this.label=label;
	this.value=code;
	this.indicators=new Array();
	this.selectedIndicators=new Array();
	this.numberIndicators =0;
	this.control=new Array();
	this.numberControls=0;
	this.stop=true;
}
new IndicatorGroup(tabMsg.get("indGpo"),null);
IndicatorGroup.prototype.defaultLabel=tabMsg.get("indicator");;
IndicatorGroup.prototype.fieldDB="CODE";
IndicatorGroup.prototype.add=indicatorGroupAddIndicator;
IndicatorGroup.prototype.selectIndicator=indicatorGroupSelectIndicator;
IndicatorGroup.prototype.getSelectIndicator=indicatorGroupGetSelectIndicator;
IndicatorGroup.prototype.getFieldDB=indicatorGroupGetFieldDB;
IndicatorGroup.prototype.nullSelectIndicator=indicatorGroupNullSelectIndicator;
IndicatorGroup.prototype.deselectIndicator=indicatorGroupDeselectIndicator;
IndicatorGroup.prototype.getList=indicatorGroupGetList;
IndicatorGroup.prototype.getObjectList=indicatorGroupGetObjectList;
IndicatorGroup.prototype.getObjectLabel=indicatorGroupGetObjectLabel;
IndicatorGroup.prototype.setList=indicatorGroupSetList;
IndicatorGroup.prototype.getControl=indicatorGroupGetControl;
IndicatorGroup.prototype.setControl=indicatorGroupSetControl;
IndicatorGroup.prototype.getObject=indicatorGroupGetObject;
IndicatorGroup.prototype.setDefaultLabel=indicatorGroupSetDefaultLabel;
IndicatorGroup.prototype.cleanControl=nullPSelectIndicator;
IndicatorGroup.prototype.numberOfElements=indicatorGroupnumberOfElements;

function indicatorGroupnumberOfElements() {
	return(this.numberIndicators);
}

function indicatorGroupGetFieldDB() {
	return(this.fieldDB);
}

function nullPSelectIndicator() {
	nullSelectIndicator();
	nullP();
}

function indicatorGroupNullSelectIndicator() {
	this.selectedIndicators=new Array();
}

function indicatorGroupGetSelectIndicator(objInd) {
	for (var i=0;i<this.selectedIndicators.length;i++)
		if (this.selectedIndicators[i]!=null&&this.selectedIndicators[i].value==objInd)
			return (this.selectedIndicators[i])
}

function indicatorGroupSelectIndicator(indicator) {
	for (var i=0;i<this.selectedIndicators.length;i++)
		if (this.selectedIndicators[i]==null||this.selectedIndicators[i].value==indicator.value)
			return;	
	this.selectedIndicators[this.selectedIndicators.length]=indicator;
}

function indicatorGroupDeselectIndicator(indicator) {
	for (var i=0;i<this.selectedIndicators.length;i++)
		if (this.selectedIndicators[i]!=null)
			if (this.selectedIndicators[i].value==indicator){
				for (var j=0;j<this.selectedIndicators[i].control.length;j++)
					this.selectedIndicators[i].control[j].hide()
				this.selectedIndicators.pop(i);
			}
}

function indicatorGroupAddIndicator(indicator) {
	var list = new ListGen();					//*Add an Indicator in the indicator list
	list.setList(this.indicators);				//*for this group
	list.add(indicator);						//*via delegation to ListGen()
	this.setList(list.list);
	indicator.parent=this;
}

function indicatorGroupGetList() {				//Implement List.getList using the LisGen.getList
	var list = new ListGen(this.defaultLabel);	//*via delegation to ListGen()
	list.setList(this.indicators);
	return (list.getList())
}

function indicatorGroupGetObjectList() {				//Implement List.getList using the LisGen.getList
	var list = new ListGen(this.defaultLabel);	//*via delegation to ListGen()
	list.setList(this.indicators);
	return (list.getObjectList())
}

function indicatorGroupSetList(list) {					//Set the list
	this.indicators=list;
	this.numberIndicators=list.length;
}

function indicatorGroupGetControl() {					//Get the Control associate to the Subregion
	return (this.control)
}


function indicatorGroupGetObjectLabel(objValue) {					//Get the label for the object
	for (var i=0;i<this.indicators.length;i++) {
		if (this.indicators[i].value==objValue)
			return (this.indicators[i].label)
	}
	return ("")
}

function indicatorGroupGetObject(index) {					//Get the Control associate to the Subregion
	return (this.indicators[index])
}

function indicatorGroupSetControl(control){		//
	this.control[control.kind]=control;
	for (var i=0;i<this.numberIndicators;i++) {
		this.indicators[i].control[this.indicators[i].numberControls++]=control
	}
	this.numberControls++;
}

function indicatorGroupSetDefaultLabel(label){		//Implement List.getList using the LisGen.getList
	this.defaultLabel=label;
}

function categoryAssign(ind){
	switch (ind.category) {
		case 1: {
			ind.sex=true;
			ind.total='.0';
			break;
		}
		case 2: {
			ind.total='.2';
			break;
		}
		case 3: {
			ind.total='.3';
			break;
		}
		case 4: {
			ind.other=true;
			ind.total='.0';
			break;
		}
		case 5: {
			ind.other=true;
			ind.total='.0';
			break;
		}
		case 6: {
			ind.other=true;
			ind.total='.0';
			break;
		}
		case 7: {
			ind.total='';
			break;
		}
		case 9: {
			ind.total='.1%';
			break;
		}
		default: {
			ind.total='.0';
			ind.sex=false;
			ind.other=false;
			break;
		}
	}
	switch (ind.subcategory) {
		case 0: {
			ind.subtotal='.0';
			break;
		}
		case 1: {
			ind.agegpo=true;
			break;
		}
		case 3: {
			ind.subtotal='.1'
			ind.agegpo=true;
			break;
		}
		case 4: {
			ind.subtotal='.1'
			break;
		}
		case 5: {
			ind.agegpo=true;
			break;
		}
		case 6: {
			ind.agegpo=true;
			break;
		}
		case 7: {
			ind.agegpo=true;
			break;
		}
		case 18: {
			ind.agegpo=true;
			break;
		}
		case 20: {
			ind.agegpo=true;
			break;
		}
		default: {
			ind.subtotal='.'+ind.subcategory;
			break;
		}
	}
}

// New Object Indicator
function Indicator(label,value,category,subcategory) {
	this.label=value+' '+label;
	this.label2=' '+label;
	this.value=value;
	this.category=category;
	this.subcategory=subcategory;
	this.total='.0';
	this.subtotal='.0';
	this.sex=false;
	this.agegpo=false;
	this.other=false;
	this.parent=null;
	this.control=new Array;
	this.numberControls=0;
	this.stop=true;
	categoryAssign(this);
}
new Indicator(null,null,null,null);
Indicator.prototype.setControl=indicatorSetControl;
Indicator.prototype.defaultLabel=tabMsg.get("indicator");
Indicator.prototype.getList=indicatorGetList;
Indicator.prototype.getObjectList=indicatorGetObjectList;
Indicator.prototype.getValue=indicatorGetValue;
Indicator.prototype.cleanControl=nullP;

function indicatorGetList() {					//Implement List.getList using the LisGen.getList
//	this.control
	return (this.value)
}

function indicatorSetControl(control){		//
	control.setParent(this);
	control.setLevel(1);
	this.control=control;
}

function indicatorGetObjectList() {				//Implement List.getList using the LisGen.getList
	var list = new ListGen(this.defaultLabel);	//*via delegation to ListGen()
	list.setList(this);
	return (list.getObjectList())
}

function assignIndicator(vArray,lArray,aLength,valueV,valueA,labelV,labelA) {
	var aLengthT = "";
	vArray[aLength]=valueV+valueA
	if (aLength+1<10) {
		aLengthT = "  "+(aLength+1)
	} else {
		if (aLength+1<100) {
			aLengthT = " "+(aLength+1)
		} else {
			aLengthT = (aLength+1)+""
		}
	}
	lArray[aLength]=aLengthT+'. '+vArray[aLength]+labelV+labelA;
}

function indicatorGetValue(vArray,lArray,kind) {					//Get the Control associate to the Subregion
	var validity = new Array();
	validity[0]=true;
	validity[1]=this.sex;
	validity[2]=this.sex;
	validity[3]=this.agegpo;
	validity[4]=this.other;
	// Patch for manage exception for indicator E.26
	if (kind == 'fixed'&&this.total == '.1%')
		this.total='.12';
	if (kind != 'fixed'&&this.total == '.12')
		this.total='.1%';
	// End of patch
	this.control[0].value=this.total;
	if (this.sex||this.agegpo||this.other) {
		for (var i=0;i<this.numberControls;i++){
			if (validity[i])
				this.control[i].disabled=false;
			if (this.control[i].kind==kind) {
				this.control[i].show()
				if (this.control[i].control.checked&&validity[i]){
					if(this.control[i].category==1) {
						assignIndicator(vArray,lArray,vArray.length,this.value,this.control[i].value+this.subtotal,this.label2,tabMsg.get(this.control[i].label));
					} 
					if(this.control[i].category==2) {
						for (j=0;j<3;j++) {
							if (this.control[j].control.checked&&validity[j])
								assignIndicator(vArray,lArray,vArray.length,this.value,this.control[j].value+this.control[i].value,this.label2,tabMsg.get(this.control[j].label)+tabMsg.get(this.control[i].label));
						}
					}
				}
			}
		}
	} else {
		assignIndicator(vArray,lArray,vArray.length,this.value,this.total+this.subtotal,this.label2,"");
	}
	this.parent.selectIndicator(this);
}


//new object YearPeriod Implement Interfase List()
function YearPeriod(firstyear,lastyear){
	this.label=firstyear+"-"+lastyear;
	this.value=firstyear+""+lastyear;
	this.years=new Array();
	this.numberYears=0;
	this.first=firstyear;
	this.last=lastyear;
	this.stop=true;
}
new YearPeriod(null,null);
YearPeriod.prototype.numberPeriods=0;
YearPeriod.prototype.fieldDB="Anio";
YearPeriod.prototype.add=yearPeriodadd;
YearPeriod.prototype.getList=yearPeriodGetList;
YearPeriod.prototype.getObjectList=yearPeriodGetObjectList;
YearPeriod.prototype.getFieldDB=yearPeriodGetFieldDB;
YearPeriod.prototype.setList=yearPeriodSetList;
YearPeriod.prototype.defaultLabel=tabMsg.get("year");;
YearPeriod.prototype.setDefaultLabel=yearPeriodSetDefaultLabel;
YearPeriod.prototype.getObject=yearPeriodGetObject;
YearPeriod.prototype.cleanControl=nullP;
YearPeriod.prototype.numberOfElements=yearPeriodGroupnumberOfElements;

function yearPeriodGroupnumberOfElements() {
	return(this.numberYears);
}

function yearPeriodGetFieldDB() {
	return(this.fieldDB);
}

function nullP() {
	if (this.control!=null)
		for (var i=0;i<this.control.length;i++)
			this.control[i].disabled=true;
}

function yearPeriodadd() {
	for (var i=0,y=this.last;y>=this.first;i++,y--) {
		this.years[i]=new Year(y);
		this.numberYears++
	}
	this.numberPeriods++
}

function yearPeriodGetList() {
	var list = new ListGen(this.defaultLabel);	//*via delegation to ListGen()
	list.setList(this.years);
	var lastAvailable = new Array();
	lastAvailable[0]=new Year("LA");
	lastAvailable[0].label=tabMsg.get("lastAvailable");
	lastAvailable[0].value="LA";
	lastAvailable[0].action=true;
	lastAvailable[0].position=1;
	list.insertElement(lastAvailable,0);
	this.setList(list.getObjectList());
	return (list.getList())
}

function yearPeriodGetObjectList() {				//Implement List.getList using the LisGen.getList
	var list = new ListGen(this.defaultLabel);	//*via delegation to ListGen()
	list.setList(this.years);
	return (list.getObjectList())
}

function yearPeriodSetList(list) {
	this.years=list;
	this.numberYears=list.length;
}

function yearPeriodSetDefaultLabel() {
	this.defaultLabel=label;
}

function yearPeriodGetObject(index) {					//Get the Control associate to the Subregion
	return (this.years[index].getList())
}

//New Object Year
function Year(year){
	this.label=year;
	this.value=year;
	this.position=0;
	this.action=false;
}
new Year(null);
Year.prototype.getList=yearGetList;
Year.prototype.getValue=yearGetValue;
Year.prototype.cleanControl=nullP;

function yearGetList() {					//Implement List.getList using the LisGen.getList
	if (this.value=="LA")
		this.action=true;
	else
		this.action=false;
//	return (this.value)
	return (this)
}

function yearGetValue(vArray,lArray) {					//Get the Control associate to the Subregion
	var aLength=vArray.length;
	vArray[aLength]=this.value;
	lArray[aLength]="* "+this.label;
}

//Generic Method for add depents
function addDepentGen(depent) {
	this.depent[this.numberDepents]=depent;
	this.numberDepents++
	depent.parent = this;
}

//Generic Method for add depents
function removeDepentGen(depent) {
	if (removeElementArray(depent,this.depent,this.numberDepents)) {
		this.numberDepents--
		depent.parent = null;
	}
}


// Constructor for a objetec RollList (a list of possible rolls)
function RollList() {
	this.rolls = new Array();
	this.numberRolls=0;
	this.label="";
}
new RollList();
RollList.prototype.defaultLabel="";
RollList.prototype.add=rollListAdd;
RollList.prototype.remove=rollListRemove;
RollList.prototype.get=rollListGet;
RollList.prototype.getFieldDB=rollListGetFieldDB;
RollList.prototype.getByValue=rollListGetByValue;
RollList.prototype.put=rollListPut;
RollList.prototype.getList=rollListFree;
RollList.prototype.numberOfElements=rollListnumberOfElements;
RollList.prototype.setLabel=rollListSetLabel;

function rollListnumberOfElements() {
	return(this.numberRolls);
}

function rollListGetFieldDB() {
	return(false);
}

function rollListSetLabel(vlabel) {
	this.label=vlabel;
}

/*Method to add a Roll in the array of Rolls
	rolls = Array of Rolls
	roll = new roll add to the Array
*/

function rollListAdd(roll) {
	this.rolls[this.numberRolls++] = roll;
}

/* Method to remove a Roll in the array of Rolls
	rolls = Array of Rolls
	roll = roll removed in the Array
*/
function rollListRemove(roll) {
	removeElementArray(roll,this.rolls,this.numberRolls)
}

function rollListGet(rollValue) {					//To get an available roll
	var newRoll = null;
	if (rollValue!=null) {
		for (var i=0;i<this.numberRolls;i++) {
			if ((this.rolls[i].value==rollValue.value)&&(this.rolls[i].used==false)) {
				this.rolls[i].used=true;				//mark the available roll
				newRoll=this.rolls[i];
				break;
			}
		}
	}
	return (newRoll);
}

function rollListGetByValue(rollValue) {			//To get an available roll refered by value
	var newRoll = new Array();
	if (rollValue!=null) {
		newRoll.value=rollValue;
		newRoll.used=false;
		newRoll=this.get(newRoll);						//delegation
	}
	return (newRoll);
}

function rollListPut(rollValue) {					//To set a roll used to available
	if (rollValue!=null)
		for (var i=0;i<this.numberRolls;i++) {
			if (this.rolls[i].value==rollValue.value&&this.rolls[i].used) {
				this.rolls[i].used=false;			//erase mark in the used roll
				break;
			}
		}
}

function rollListFree() {							//To get the list of available values
	var list = new Array();
	list[0]= new Array();
	list[0].label=tabMsg.get("selectVar")+this.label+"--"
	list[0].value="" 
	for (var i=0;i<this.numberRolls;i++) {
		if (this.rolls[i].used)
			continue;
		list[i+1]=this.rolls[i]
	}
	return (list);
}

//Constructor of new object Roll
function Roll(label,value,object){
	this.label=label;
	this.value=value;
	this.object=object;
	this.used=false;
}
new Roll (null,null,null);
Roll.prototype.setObject=rollSetObject;

function rollSetObject(object) {		//-To set the object for respond the selection
	this.object=object;					//-of this roll
}

// Constructor for a MenuOpt object
function MenuOpt(controlForm,multipleSelect,multipleDepent,multiRoll,kind,text,image) {
	this.object=new Array;
	this.numberObjects=0;
	if (controlForm!=null) {							// Select control in the HTML associate to the Menu
		this.controlForm = MM_findObj(controlForm);
	} else
		this.controlForm = null;
	this.multipleSelect = multipleSelect;	// Multiselect TRUE/FALSE
	this.value = new Array;				// Define values for the Menu if multiselect is true
	this.selectedIndex = 0;					// Index of the value selected in the Select control
	this.parent =null;						// Reference to the parent of this Menu
	this.multipleDepent = multipleDepent;	// Multidepent TRUE/FALSE
	this.depent = new Array;			// Reference to the Menu objects depented of the Menu
	this.roll = null;						// Roll of the Menu
	this.multiRoll = multiRoll;
	if (multiRoll)
		this.rolls = rollsMenu;				// Array of possible rolls
	this.observers = new Array();			// Observers for this Menu
	this.numberObservers = 0;
	this.numberDepents = 0;
	this.level=0;
	this.kind = kind;
	this.label=new Array();
	this.text=text;
	if (image!=null)
		this.image=MM_findObj(image);
	else
		this.image='';
	this.duplicates=false;
	this.sort=false;
}
new MenuOpt(null,false,false,false,null);		// Construct a null Menu to start the Prototype Menu
MenuOpt.prototype.sql = null;		// sql Object
MenuOpt.prototype.setObject = menuOptSetObject;
MenuOpt.prototype.clearObject = menuOptClearObject;
MenuOpt.prototype.change = doMenu;			// Method for change the options in the Menu
MenuOpt.prototype.hide = hide;
MenuOpt.prototype.show = menuOptShow;
MenuOpt.prototype.fillMenu = fillOptMenuSelect;
MenuOpt.prototype.setMultipleSelect = menuOptSetMultipleSelect;
MenuOpt.prototype.cleanObject = nullSelectMenu;
MenuOpt.prototype.addDepent = menuOptAddDepentGen;
MenuOpt.prototype.removeDepent = menuOptRemoveDepentGen;
MenuOpt.prototype.addObserver = addMenuObserver;
MenuOpt.prototype.removeObserver = removeMenuObserver;
MenuOpt.prototype.sqlSet = menuOptSqlSet;
MenuOpt.prototype.updateObservers = menuOptUpdateObservers;
MenuOpt.prototype.setIndexbyValue = menuOptSetIndexbyValue;
MenuOpt.prototype.setSource = menuOptSetSource;
MenuOpt.prototype.setControl = menuOptSetControl;
MenuOpt.prototype.setKind = menuOptSetKind;
MenuOpt.prototype.setSelected = menuOptSetSelected;

function menuOptSetIndexbyValue(value) {						//-to Select in the controlForm all the values
	var j=0;
	var list=new Array();
	for (var i=1;i<this.controlForm.options.length;i++) {
		if (this.controlForm.options[i].value==value[j]) {
			this.controlForm.options[i].selected=true;
			j++
		}
	}
}

function addMenuObserver(observer) {						//To add a observer of this menu
	this.observers[this.numberObservers++] = observer;
}

function removeMenuObserver(observer) {						//To remove a observer of this menu
	removeElementArray(observer,this.observers,this.numberObservers)
}

function menuOptSetObject(object) {							//To set the objects refered for this menu 
	this.object[this.numberObjects++]=object;
}

function menuOptClearObject() {							//To set the objects refered for this menu 
	this.numberObjects=0;
	this.object=new Array();
}

function menuOptSetControl(control) {							//To set the control refered for this menu 
	if (control!=null) {										// Select control in the HTML associate to the Menu
		this.controlForm = MM_findObj(control);
	} else
		this.controlForm = null;
}

function menuOptSetMultipleSelect(multiple) {					//To set the multiple select property
	if (multiple!=null) {										// Select control in the HTML associate to the Menu
		this.multipleSelect = multiple;
		this.controlForm.size=3
	} else {
		this.multipleSelect = false;
		this.controlForm.size=1;
	}
}

function menuOptSetSelected() {							//To set the objects refered for this menu 
	var j=0;
	for (var i=1;i<this.controlForm.options.length;i++) {
		this.controlForm.options[i].selected=false;
		if (this.controlForm.options[i].value==this.value[j]) {
			this.controlForm.options[i].selected=true;
			j++
		}
	}
}

function menuOptSetSource(source) {							//To set the objects refered for this menu 
	this.cleanObject();
	this.object[0]=source;
	this.fillMenu(source.getList());
	this.object[0].stop=true;
}

//MenuOpt.prototype.change = doMenu  Method for change the options in the Menu
function doMenu() {
	//alert("El tipo de este menu es: "+this.kind)
	if (this.object!='')
	if (this.object[0].stop) {
		if (this.controlForm.selectedIndex!=0) {
			this.value.length=0;
			this.label.length=0;
			this.selectedIndex=this.controlForm.selectedIndex;
			for (var i=0;i<this.object.length;i++)
				for (var j=0;j<this.object[i].numberOfElements();j++)
					this.object[i].getObject(j).cleanControl();
			j=0;
			k=0;
			act=null
			for (var i=0;i<this.controlForm.options.length;i++) {
				if (!this.multipleSelect&&i!=this.selectedIndex){
					this.controlForm.options[i].selected=false;
					continue;
				}
				if (this.object[j].getObjectList().length<i-k) {
					k+=this.object[j].getObjectList().length;
					j++;
				}
				if (this.controlForm.options[i].selected) {
					this.object[j].getObject(i-k-1).getValue(this.value,this.label,this.kind);
					act=this.object[j].getObject(i-k-1).action;
					if (act!=null){
						if (act) {
							this.sql.actualSource=1;
							this.setSelected();
							break;
						} else
							this.sql.actualSource=0;
					}
					if (this.duplicates) {
						cList=new ListGen();
						cList.setList(this.value);
						cList.eliminateDuplicates();
						this.value=cList.getObjectList();
						cList.setList(this.label);
						cList.eliminateDuplicates();
						this.label=cList.getObjectList();
					} 
					if (this.sort) {
						this.value.sort();
						this.label.sort();
					}
				} else {
					if (this.object[j].selectedIndicators!=null) {
						this.object[j].deselectIndicator(this.controlForm.options[i].value);
					}
				}
			}
			this.sql.set(this.kind,this.value,null,this.label,this.text);
		} else {
			this.cleanObject();							// to empty the menu
		}
		return;
	}
	this.cleanObject();							// to empty the menu
	if (this.multiRoll) {						// if the menu is multiRoll free the roll
		this.rolls.put(this.roll);
	}
	if (this.controlForm.selectedIndex==0){		// if the selected option is the first on (-Selected-)
		if (this.multiRoll)						//
			this.roll=null;
			this.updateObservers();
		this.hide;
		return;
	}
	this.selectedIndex=this.controlForm.selectedIndex;
	var j=0;
	for (var i=0;i<this.controlForm.options.length;i++) {
		if (!this.multipleSelect&&i!=this.selectedIndex){
			this.controlForm.options[i].selected=false;
			continue;
		}
		if (this.controlForm.options[i].selected) {
			this.value[j] = this.controlForm.options[i].value;
			this.label[j] = this.controlForm.options[i].label;
			j++
		} else {
			if (this.object[0].list!=null&&i!=0) 
				if (this.object[0].list[i-1].selectedIndicators!=null) {
					this.object[0].list[i-1].nullSelectIndicator();
				}
		}
	}
	this.controlForm.options.length=0;
	if (this.object.length>1) {
		var cList = new ListGen(this.object[0].label);
		for (var i=0;i<this.object.length;i++)
			cList.aggregateList(this.object[i].getObjectList(),false)
		opts=cList.getList();
	} else {
		opts=this.object[0].getList();
	}
	this.fillMenu(opts);
	var list=new Array();
	this.setSelected();
	if (this.selectedIndex != 0) {
		if (this.multiRoll) {
			this.roll=this.rolls.getByValue(this.value[0]);
			this.roll.used=true;
			this.depent[0].object[0]=this.roll.object;
			if (this.depent[0].object[0].control!=null)
				if (this.depent[0].object[0].control[this.kind]!=null)
					this.depent[0].object[0].control[this.kind].show();
		} else {
			var cList = new ListGen(this.object[0].getObject(0).defaultLabel);							//To join the multiselection list
			j=0;
			for (var i=1;i<this.controlForm.options.length;i++) {
				if (this.controlForm.options[i].value==this.value[j]) {
					this.depent[0].object[j]=this.object[0].getObject(i-1);
					cList.aggregateList(this.depent[0].object[j].getObjectList(),false);
					j++
				}
			}
		}
		if (!this.multiRoll) {
			list=cList.getList();
		}
		this.depent[0].fillMenu(list);
	} else
		this.depent.cleanObject();
	this.updateObservers();
	for(var i=0;i<this.numberDepents;i++) {
		if (this.multiRoll) {
			opts=this.depent[i].object[0].getList()
			this.depent[i].fillMenu(opts);
		}
	}
}

function menuOptUpdateObservers() {
	var opts=null;
	var ind=new Array();
	var used=null;
	for(var i=0;i<this.numberObservers;i++)
		if (this.multiRoll) {
			if (this.observers[i].roll!=null) {
				used=null;
				for(var j=0;j<this.observers[i].value.length;j++)  //To preserve the selected items
					ind[j]=this.observers[i].value[j];
				if (this.observers[i].roll.used) {
					used=this.observers[i].roll;
					this.observers[i].rolls.put(used);
				}
			}
			this.object[0].label=this.observers[i].kind;
			opts=this.object[0].getList();
			this.observers[i].fillMenu(opts);
			this.observers[i].rolls.get(used);
			this.observers[i].setIndexbyValue(ind);
		}
}



function menuOptAddDepentGen(depent) {
	this.depent[this.numberDepents]=depent;
	this.numberDepents++
	depent.parent = this;
	depent.level=this.level+1;
}

function menuOptSetKind(kind) {
	this.kind=kind;
	this.sql.imageName[this.kind]=this.image;
	if (this.parent!=null)
		this.parent.kind=kind;
	for(var i=0;i<this.numberDepents;i++)
		if (this.depent[i].kind!=kind){
			this.depent[i].setKind(kind);
		}
}

function menuOptRemoveDepentGen(depent) {
	if (removeElementArray(depent,this.depent,this.numberDepents)) {
		this.numberDepents--
		depent.parent = null;
		depent.level=0;
	}
}


//MenuOpt.prototype.sqlSet = menuOptSqlSet;
function menuOptSqlSet(sqlObject) {
	MenuOpt.prototype.sql = sqlObject;
}

// MenuOpt.prototype.fillMenu = fillOptMenuSelect;
function fillOptMenuSelect(optsMenu) {
	if (this.controlForm!=null) {
	this.controlForm.options.length = 0
	j=0;
	l=0;
	k=0;
	for (var i=0;i<(optsMenu.length);i++){
		if (optsMenu[i]!=null) {
			this.controlForm.options[j]=new Option(optsMenu[i].label,optsMenu[i].value);
			if (this.object[l]!=null) {
				if (i>this.object[l].getObjectList().length+k) {
					k+=this.object[l].getObjectList().length;
					l++;
				}
				if (this.object[l].selectedIndicators!=null) {
					if (this.object[l].getSelectIndicator(optsMenu[i].value)!=null) {
						this.controlForm.options[j].selected=true;
						this.object[l].getObject(j-k-1).getValue(optsMenu[i].value,optsMenu[i].label,this.kind);
					}
				}
			}
			j++
		}
	}
	var l=0;
	if (this.object[0]!=null) {
		if (this.object[0].selectedIndicators!=null) {
			vlist=new Array();
			llist=new Array();
			for (var i=0;i<this.object.length;i++)  
				if (this.object[i].selectedIndicators!=null) {
					for (var j=0;j<this.object[i].selectedIndicators.length;j++) {
						if (this.object[i].selectedIndicators[j]!=null) {
							this.object[i].selectedIndicators[j].getValue(vlist,llist,this.kind);					
						}
					}
				}
			this.sql.set(this.kind,vlist,null,llist,this.text);
		}
	}
	this.show();
	}
}

//MenuOpt.prototype.cleanObject = nullSelectMenu;
function nullSelectMenu() {
	if (this.depent!=null) {
		for (var i=0;i<this.depent.length;i++){
			this.depent[i].cleanObject();
			this.depent[i].object=new Array();
			this.depent[i].numberObjects=0;
			this.depent[i].hide();
			if (this.depent[i].controlForm!=null)
				for (var j=0;j<this.depent[i].controlForm.options.length;j++)
					this.depent[i].controlForm.options[j].selected=false;
		}
	}
	this.selectedIndex=0;
	this.value.length=0;
	if (this.sql!=null)
		this.sql.set(this.kind,null,null,null,this.text);
}

function hide(){
	if (this.depent!=null) {
		for (var i=0;i<this.depent.length;i++)
			this.depent[i].hide();
	}
	if (!is_nav4){
		this.controlForm.style.visibility = 'hidden';
		this.controlForm.style.display = 'none';
	}
}

function menuOptShow(){
	if (!is_nav4){
		this.controlForm.style.visibility = 'visible';
		this.controlForm.style.display = '';
	}
}

//MenuOpt.prototype.onChangeSub = onChangeSubMenu;
//Definition of new Class CheckOpt
function CheckOpt(id,kind,type,value,category,label) {
	if (id!=null)
		this.control = MM_findObj(id);
	else
		this.control = null;
	this.parent = null;
	this.kind = kind;
	this.type = type;
	this.multiQuery = false;
	this.object=new Array();
	this.value=value;
	this.category=category;
	this.label=label;
	this.numberObjects=0;
	this.disabled=true;
}
new CheckOpt(null,null);
CheckOpt.prototype.show = showSpan;
CheckOpt.prototype.hide = spanOptHide;
CheckOpt.prototype.onCheck = CheckOptOnCheck;
CheckOpt.prototype.check = checkOpCheck;
CheckOpt.prototype.setControl = checkOpttSetControl;
CheckOpt.prototype.setKind = checkOpttSetKind;
CheckOpt.prototype.setMultiquery = checkOpttSetMultiquery;
CheckOpt.prototype.setObject = checkOptSetObject;
CheckOpt.prototype.cleanObject = checkOptCleanObject;

function checkOpttSetMultiquery(bValue) {
	this.multiQuery = bValue;
}

function checkOptCleanObject() {
	if (this.control!=null)
		if (this.control.defaultChecked)
			this.control.checked = true
		else
			this.control.checked = false
		this.disabled=true;
}

function checkOptSetObject(object) {
 	this.object[this.numberObject++] = object;
	object.setControl(this);
}

//SpanOpt.prototype.check = spanOpCheck;
function checkOpCheck(obj,parameter) {
	if (this.control.checked)
		if (parameter!=null)
			obj.fillMenu(parameter);
		else
			obj.cleanObject();
}

function CheckOptOnCheck() {
	if ((this.kind=="fixed"&&this.multiQuery)||this.disabled) {
		this.control.checked=false;
		alert(tabMsg.get("alertValidOption"));
		return;
	}
	if (this.parent.object!="") { 
		if (this.parent.object[0].value!="") {
			this.parent.change();
			if (this.parent.parent.sql!=null&&this.type=='A'){
				if (this.control.checked) 
					this.parent.parent.sql.query=true;
				else
					this.parent.parent.sql.query=false;
			}
		}
	} else {
		this.control.checked=false;
		alert(tabMsg.get("alertSelectFirst"));
	}
}

function checkOpttSetControl(control) {							//To set the control refered for this checkbox 
	if (control!=null) {										// Select control in the HTML associate to the checkbox
		this.control = MM_findObj(control);
	} else
		this.control = null;
}

function checkOpttSetKind(kind) {							//To set the kind refered for this checkbox
	if (debug)
		alert(this.kind+" este check cambiando a: "+kind+" parent:"+this.parent);
	this.kind=kind;
	if (this.parent!=null)
		this.parent.kind=kind;
}

//Definition of new Class SpanOpt
function SpanOpt(id,type,defaults,kind) {
	if (id!=null)
		this.control = MM_findObj(id);
	else
		this.control = null;
	this.name=id;
	this.depent = new Array();
	this.parent = null;
	this.numberDepents = 0;
	this.multipleDepent = true;
	this.type = type;
	this.defaults = defaults;
	this.object=new Array();
	this.numberObjects=0;
	this.kind=kind;
}
new SpanOpt(null,'','','');
SpanOpt.prototype.defaultOpt = tabMsg.get("total");
SpanOpt.prototype.show = showSpan;
SpanOpt.prototype.cleanObject = nullSpan;
SpanOpt.prototype.hide = spanOptHide;
SpanOpt.prototype.setControl = spanOptSetControl;
SpanOpt.prototype.addDepent = addDepentGen;
SpanOpt.prototype.removeDepent = removeDepentGen;
SpanOpt.prototype.fillMenu = fillSpan;
SpanOpt.prototype.setObject = spanOptSetObject;
SpanOpt.prototype.setKind = spanOptSetKind;

function spanOptSetKind(kind) {							//To set the kind refered for this checkbox
	if (debug)
		alert(this.kind+" este span cambiando a: "+kind+ " NumDepents: "+this.numberDepents+" parent:"+this.parent);
	this.kind=kind;
	for(var i=0;i<this.numberDepents;i++)
		if (this.depent[i].kind!=kind)
			this.depent[i].setKind(kind);
}

//SpanOpt.prototype.show = showSpan;
function showSpan() {
	//MM_showHideLayers(this.name,'','show')
}

function spanOptSetControl(control) {							//To set the control refered for this menu 
	if (control!=null) {										// Select control in the HTML associate to the Menu
		this.control = MM_findObj(control);
	} else
		this.control= null;
}

//SpanOpt.prototype.cleanObject = nullSpan;
function nullSpan() {
	for (var i=0;i<this.numberDepents;i++) {
		if (this.depent[i]==null)
			break;
		if (this.depent[i].control==null)
			break;
		this.depent[i].cleanObject();
	}
}

function spanOptHide() {
	//MM_showHideLayers(this.name,'','hide')
}

function spanOptSetObject(object) {
 	this.object[this.numberObject++] = object;
	object.setControl(this);
}

//SpanOpt.prototype.fillMenu = fillSpan;
function fillSpan(optsMenu) {
	if (this.object[this.type]||this.type==this.defaultOpt){
		this.show();
		this.parent.object[0].stop=true;
	}
	if (this.defaults != null)
		this.defaults.show();
}

//Definition of new Class SqlCommandText
function SQLCommandText(select,from) {
	if (select!=null)
		this.select='SELECT '+ select;
	else
		this.select='SELECT *';
	if (from!=null)
		this.from=' FROM '+ from;
	else
		return (false)
	this.where=null;
	this.groupBy=null;
	this.orderBy=null;
	if (typeof(_bSqlCommandTextPrototypeCalled) == 'undefined')
		initSqlCommandText();
	return (true)
}
new SQLCommandText(null,null);
function initSqlCommandText() {
	_bSqlCommandTextPrototypeCalled=true;
	SQLCommandText.prototype.setWhere = SqlCommandTextSetWhere;
	SQLCommandText.prototype.privateSetWhere = privateSqlCommandTextSetWhere;
	SQLCommandText.prototype.addWhere = SqlCommandTextAddWhere;
	SQLCommandText.prototype.setGroupBy = SqlCommandTextSetGroupBy;
	SQLCommandText.prototype.setOrderBy = SqlCommandTextSetOrderBy;
	SQLCommandText.prototype.get = SqlCommandTextGet;
	SQLCommandText.prototype.getSelect = SqlCommandTextGetSelect;
	SQLCommandText.prototype.getWhere = SqlCommandTextGetWhere;
}

function privateSqlCommandTextSetWhere(varName, varArrayValues, varOperator, type) {
	if (varOperator==null||varOperator=='')
		varOperator='OR';
	this.where += "("
	for(var i=0;i<varArrayValues.length;i++){
		if (type=='number')
			this.where +=varName+"="+varArrayValues[i];
		else
			this.where +=varName+" LIKE \'"+varArrayValues[i]+"\'";
		if (i!=(varArrayValues.length-1))
			this.where += " "+varOperator+" "
		else
			this.where += ")"
	}
}
function SqlCommandTextSetWhere(varName, varArrayValues, varOperator, type) {
	this.where=' WHERE ';
	this.privateSetWhere(varName, varArrayValues, varOperator, type);
}
function SqlCommandTextAddWhere(varName, varArrayValues, varOperator, varOperator2, type) {
	this.where+=' '+varOperator2+' ';
	this.privateSetWhere(varName, varArrayValues, varOperator);
}
function SqlCommandTextSetGroupBy(groupByValues) {
	this.groupBy= ' GROUP BY '+groupByValues;
}
function SqlCommandTextSetOrderBy(orderByValues) {
	this.orderBy= ' ORDER BY '+orderByValues;
}
function SqlCommandTextGet() {
	sqlTxt='';
	if (this.from==null)
		return (null)
	sqlTxt+=this.select+this.from;
	if (this.where!=null)
		for (var i=0;i<this.where.length;i++)
			sqlTxt+=this.where[i];
	if (this.groupBy!=null)
		sqlTxt+=this.groupBy;
	if (this.orderBy!=null)
		sqlTxt+=this.orderBy;
	return (sqlTxt);
}
function SqlCommandTextGetSelect() {
	return (this.select+' FROM ');
}
function SqlCommandTextGetWhere() {
	return (this.where);
}
/*function SqlCommandTextGetWhere() {
	sqlTxt='';
	for (var i=0;i<this.where.length;i++)
		sqlTxt+=this.where[i];
	return (sqlTxt);
}*/

//Definition of new Class SqlCommand
function SqlCommand(formSource,formTarget) {
	this.boxText='<form id="sqlCommand" name="sqlCommand">';
	this.boxText+='<strong>'+tabMsg.get("review")+'</strong><br><center>';
	this.boxText+='<TEXTAREA name="commandSelect" id="commandSelect" style="WIDTH: 100%; COLOR: navy" rows=20 readOnly cols=58>Selection: Empty</TEXTAREA>';
	this.boxText+='<input id="resetSelect" onclick="return (window.close());" type="reset" value="'+tabMsg.get("closeWindowB")+'" name="closeSelect"></center></form>';
	if (formSource!=null)
		this.formSource=MM_findObj(formSource);
	else
		this.formSource='';
	if (formTarget!=null)
		this.formTarget=MM_findObj(formTarget);
	else
		this.formTarget='';
	this.imageName=new Array();
	this.imageSrcIncomplete = new Array();
	this.imageSrcComplete = new Array();
	this.columns = new Array();
	this.labelColumns = new Array();
	this.labelColumns[0] = null;
	this.numberColumns = 0;
	this.rows = new Array();
	this.labelRows = new Array();
	this.labelRows[0] = null;
	this.numberRows = 0;
	this.fixed = null;
	this.labelConstant = null;
	this.source = new Array();
	this.numberSources = 0;
	this.actualSource = 0;
	this.labels=new Array();
	this.query=false;
	this.str="";
}
new SqlCommand(null,null);
SqlCommand.prototype.set = SqlCommandSet;
SqlCommand.prototype.setVariables = SqlCommandSetVariables;
SqlCommand.prototype.setException = SqlCommandSetException;
SqlCommand.prototype.addColumn = SqlCommandaddColumn;
SqlCommand.prototype.removeColumn = SqlCommandremoveColumn;
SqlCommand.prototype.addRow = SqlCommandaddRow;
SqlCommand.prototype.removeRow = SqlCommandremoveRow;
SqlCommand.prototype.setForm = SqlCommandsetForm;
SqlCommand.prototype.setColumns = SqlCommandsetColumns;
SqlCommand.prototype.setRows = SqlCommandsetRows;
SqlCommand.prototype.setConstant = SqlCommandsetConstant;
SqlCommand.prototype.setSource = SqlCommandsetSource;
SqlCommand.prototype.addImage = SqlCommandAddImage;
SqlCommand.prototype.swapImage = SqlCommandSwapImage;
SqlCommand.prototype.createSQLSentence = SqlCommandcreateSQLSentence;
SqlCommand.prototype.clearAll = SqlCommandclearAll;
SqlCommand.prototype.add = SqlCommandadd;
SqlCommand.prototype.remove = SqlCommandremove;
SqlCommand.prototype.changeColor = SqlCommandChangeColor;
SqlCommand.prototype.setItem = SqlCommandSetItem;
SqlCommand.prototype.getReview = SqlCommandGetReview;

function SqlCommandGetReview(){
	var style='';
	if (!is_nav)
		style='/CORPORATE/paho_main.css'
	var winDef=new windowMsg('winDef2',style,'450','400');
	winDef.setTitle("Query Review");
	winDef.setHTML(this.boxText,null,null,true);
	var obj=MM_findObj('commandSelect',winDef.window.document);
	obj.value=this.str
}

function SqlCommandAddImage(kind,imageName,imageSrcIncomplete,imageSrcComplete){
	if (imageName!=null)
		this.imageName[kind]=MM_findObj(imageName);
	else
		this.imageName[kind]='';
	this.imageSrcIncomplete[kind] = imageSrcIncomplete;
	this.imageSrcComplete[kind] = imageSrcComplete;
}

function SqlCommandSwapImage(kind,imageName,imageSrcIncomplete,imageSrcComplete){
	if (imageName!=null)
		this.imageName[kind]=MM_findObj(imageName);
	else
		this.imageName[kind]='';
	this.imageSrcIncomplete[kind] = imageSrcIncomplete;
	this.imageSrcComplete[kind] = imageSrcComplete;
}
	
//SqlCommand.prototype.set = SqlCommandset;
function SqlCommandadd(kind,value) {
	switch(kind) {
		case 'columns':
			{
				if (value!=null)
					this.addColumn(value);
				break;
			}
		case 'rows':
			{
				if (value!=null)
					this.addRow(value);
				break;
			}
	}
}

function SqlCommandremove(kind,value) {
	switch(kind) {
		case 'columns':
			{
				if (value!=null)
					this.removeColumn(value);
				break;
			}
		case 'rows':
			{
				if (value!=null)
					this.removeRow(value);
				break;
			}
	}
}

function SqlCommandChangeColor(color,field,kind,image) {
	var obj=MM_findObj(field);
	if (obj!=null)
		obj.style.color=color;
	this.imageName[kind].src=image;
}

function SqlCommandSetItem(vArray,labelsArray,kind) {
	switch(kind) {
		case 'fixed': {
			this.setConstant(vArray[0],labelsArray[0]);
			break;
		}
		case 'columns': {
			this.setColumns(vArray,labelsArray);
			break;
		}
		case 'rows': {
			this.setRows(vArray,labelsArray);
		}
	}
}

function SqlCommandSet (kind, vArray, labelsArray, p, text) {
	labelsArray=p;
	var nArray = new Array();
	if (vArray==null||vArray=="") {
		nArray[0]=null;
		var labelsArray = new Array();
		labelsArray[0]=tabMsg.get("empty");
	 	this.changeColor("red",text,kind,this.imageSrcIncomplete[kind]);
	} else {
		nArray=vArray;
	 	this.changeColor("green",text,kind,this.imageSrcComplete[kind]);
	}
	this.setItem(nArray,labelsArray,kind);
	if (this.formSource!=null) {
		if (this.labelConstant==null){
			this.labelConstant=tabMsg.get("empty");
		}
		if (this.labelColumns[0]==null){
			this.labelColumns.length=0;	
			this.labelColumns[0]=tabMsg.get("empty");
		}
		if (this.labelRows[0]==null){
			this.labelRows.length=0;	
			this.labelRows[0]=tabMsg.get("empty");
		}
		if (this.labelConstant!=tabMsg.get("empty")&&this.labelColumns[0]!=tabMsg.get("empty")&&this.labelRows[0]!=tabMsg.get("empty"))
			this.formSource.submitSelect.disabled=false;
		else
			this.formSource.submitSelect.disabled=true;
		this.str=tabMsg.get("fixed")+this.labelConstant+tabMsg.get("cols");
		for (var i=0;i<this.labelColumns.length;i++)
			if (this.labelColumns[i]!=tabMsg.get("empty"))
				this.str+=" "+this.labelColumns[i]+"\n"
		this.str+=tabMsg.get("rows");
		for (var i=0;i<this.labelRows.length;i++)
			if (this.labelRows[i]!==tabMsg.get("empty"))
				this.str+=" "+this.labelRows[i]+"\n"
	}
}

//SqlCommand.prototype.clearAll = SqlCommandclearAll;
function SqlCommandclearAll() {
	var nArray = new Array();
	this.setConstant(null);
	this.setSource(null);
	this.setColumns(nArray);
	this.setRows(nArray);
}

//SqlCommand.prototype.setVariables=SqlCommandSetVariables;
function SqlCommandSetVariables(variables) {
	SqlCommand.prototype.variables = variables;
}

//SqlCommand.prototype.setException = SqlCommandSetException;
function SqlCommandSetException(exception) {
	SqlCommand.prototype.exception = exception;
}

// Generic addElementArray;
function addElementArray(element,vArray,numberElement) {
	vArray[numberElement++] = element
}

//SqlCommand.prototype.addColumn = SqlCommandaddColumn;
function SqlCommandaddColumn(column) {
	addElementArray(column,this.columns,this.numberColumns);
}

//SqlCommand.prototype.addRow = SqlCommandaddRow;
function SqlCommandaddRow(row) {
	addElementArray(row,this.rows,this.numberRows);
}


//SqlCommand.prototype.removeColumn = SqlCommandremoveColumn;
function SqlCommandremoveColumn(column) {
	removeElementArray(column,this.columns,this.numberColumns);
}

//SqlCommand.prototype.removeRow = SqlCommandremoveRow;
function SqlCommandremoveRow(row) {
	removeElementArray(row,this.rows,this.numberRows);
}

//SqlCommand.prototype.setConstant = SqlCommandsetConstant;
function SqlCommandsetConstant(fixedValue,fixedLabel) {
	this.fixed=fixedValue;
	this.labelConstant=fixedLabel;
}

function SqlCommandsetForm(form) {
	this.formTarget=form;
}

//SqlCommand.prototype.setSource = SqlCommandsetSource;
function SqlCommandsetSource(sourceValue) {
	this.source[this.numberSources++]=sourceValue;
}

//SqlCommand.prototype.setColumns = SqlCommandsetColumns;
function SqlCommandsetColumns(columns,columnsLabel) {
	this.columns.length=0;
	this.labelColumns.length=0;
	for (var i=0; i<columns.length; i++) {
		this.columns[i]=columns[i];
		this.labelColumns[i]=columnsLabel[i];
	}
	this.numberColumns=columns.length-1;
}

//SqlCommand.prototype.setRows = SqlCommandsetRows;
function SqlCommandsetRows(rows,rowsLabel) {
	this.rows.length=0;
	this.labelRows.length=0;
	for (var i=0; i<rows.length; i++) {
		this.rows[i]=rows[i];
		this.labelRows[i]=rowsLabel[i];
	}
	this.numberRows=rows.length-1;
}

function fieldTable(field,hiddenControl) {
	value=field.object[0].getFieldDB();
	if (value==false){
		if (field.value!=null)
			value=field.value[0]
		else
			value=field
	}
	hiddenControl.value=value
	return(hiddenControl.value);
}

/*function whereText(fieldVar,vArray) {
	var sqlCommandTable = "";
	sqlCommandTable += "("
	for(i=0;i<vArray.length;i++){
		sqlCommandTable +=fieldVar+" LIKE \'"+vArray[i]+"\'"
		if (i!=(vArray.length-1))
			sqlCommandTable += " OR "
		else
			sqlCommandTable += ")"
	}
	return(sqlCommandTable);
}*/

//SqlCommand.prototype.createSQLSentence = SqlCommandcreateSQLSentence;
function SqlCommandcreateSQLSentence(vfix,vcols,vrows) {
	exception=false;
	if ((this.rows.length*this.columns.length)>MAXNUMCELLS) {
		alert('You are selected: '+this.rows.length+' rows and '+this.columns.length+' for a total number of cells in the table ('+this.rows.length*this.columns.length+'). To be able to process you request, please select less variables')
		return false;
	}
	var sqlCommandString = new SQLCommandText (this.variables,this.source[this.actualSource]);
	this.formTarget.sqlCommandText1.value=sqlCommandString.getSelect();
	this.formTarget.sqlCommandSource.value=this.source[this.actualSource]
	fixVar = fieldTable(vfix,this.formTarget.fixArray);
	colVar = fieldTable(vcols,this.formTarget.colsql);
	rowVar = fieldTable(vrows,this.formTarget.rowsql);
	this.formTarget.fixArray.value=fixVar;
	if (this.columns[0]!=null) {
		if (this.columns[0]!=this.exception) {
			sqlCommandString.setWhere(colVar,this.columns,'OR')
			this.formTarget.colArray.value=this.columns.toString();
		} else {
			exception=true;
			this.formTarget.colArray.value="";
		}
	} else {
		alert(tabMsg.get("alertSelectCols"));
		return false;
	}
	if (this.rows[0]!=null) {
		if (this.rows[0]!=this.exception) {
			if (exception)
				sqlCommandString.setWhere(rowVar,this.rows,'OR','AND')
			else 
				sqlCommandString.addWhere(rowVar,this.rows,'OR','AND')
			this.formTarget.rowArray.value=this.rows.toString();
		} else {
			this.formTarget.rowArray.value="";
		}
	} else {
		alert(tabMsg.get("alertSelectRows"));
		return false;
	}
	if (this.fixed!=null) {
		if (this.fixed!=this.exception){
			sqlFixArray=new Array();
			sqlFixArray[0]=this.fixed
			this.formTarget.fixsql.value=this.fixed;
			this.formTarget.conector.value = " AND "
			this.formTarget.sqlCommandSelector.value ="("+fixVar+" LIKE '"+this.fixed+"')"
		} else {
			this.formTarget.fixsql.value=this.fixed;
			this.formTarget.conector.value = "";
			this.formTarget.sqlCommandSelector.value =""
		}
	} else {
		alert(tabMsg.get("alertSelectConst"));
		return false;
	}
	this.formTarget.query.value=this.query;
	this.formTarget.sqlCommandText2.value=sqlCommandString.getWhere();
	if (debug){
		alert("Query= "+this.formTarget.sqlCommandText1.value+" "+this.formTarget.sqlCommandSource.value+" "+this.formTarget.sqlCommandText2.value+" "+this.formTarget.sqlCommandSelector.value+" "+this.formTarget.conector.value+" "+this.formTarget.query.value);
		alert("fixsql= "+this.formTarget.fixsql.value+" "+"fixArray= "+this.formTarget.fixArray.value+" "+"rowsql= "+this.formTarget.rowsql.value+" "+"rowArray= "+this.formTarget.rowArray.value+" "+"colsql= "+this.formTarget.colsql.value+" "+"colsql= "+this.formTarget.colArray.value);
	}
	this.formTarget.submit();
	//this.formSource.reset();
	return false;
}

function onResetthisForm() {
	if (this.formTarget!=null)
		this.formTarget.reset();
	return true;
}

function fillOptsSeq(rolls,optsArray,first,last) {
	optsMenu = new Array()
	j = first
	for(i=first;i<last;i++) {
		if (rolls != null)
			if (rolls[optsArray[i].value]==null) continue;
		optsMenu[j]= new Array()
		optsMenu[j].label=optsArray[i].label;
		optsMenu[j].value=optsArray[i].value;
		j++
	}
	return(optsMenu);
}

function Connector(){
	this.radioSet=new Array();
	this.menuSet=new Array();
	this.numElements=0;
}
new Connector();
Connector.prototype.type=new Array();
Connector.prototype.typeMenu=new Array();
Connector.prototype.add=connectorAdd;
Connector.prototype.assign=connectorAssign;
Connector.prototype.get=connectorGet;
Connector.prototype.addTypeMenu=connectorAddTypeMenu;
Connector.prototype.remove=connectorAdd;
Connector.prototype.getElement=connectorGetElement;
Connector.prototype.update=connectorUpdate;
Connector.prototype.type[0]='fixed';
Connector.prototype.type[1]='rows';
Connector.prototype.type[2]='columns';

function connectorGetElement(list,obj){
	for (var i=0;i<list.length;i++) 
		if (list[i][0]==obj[0])
			return i;
}

function connectorAdd(radio,menu){
	this.radioSet[this.numElements]=radio;
	this.menuSet[this.numElements++]=menu;
}

function connectorAddTypeMenu(type,menu){
	this.typeMenu[type]=new Array();
	this.typeMenu[type]=menu;
}

function connectorAssign(type,menu){
	this.typeMenu[type]=menu;
}

function connectorGet(type){
	return this.typeMenu[type];
}


function connectorRemove(radio,menu){
	this.radioSet.pop(this.getElement(this.radioSet,radio));
	this.menuSet.pop(this.getElement(this.menuSet,menu));
}

function connectorUpdate(radio,index){
/*	var j=this.getElement(this.radioSet,radio);
	for (var i=0;i<radio.length;i++) {
		if (radio[i].checked) {
			if (i==0)
				this.menuSet[j].setMultipleSelect(null);
			else
				this.menuSet[j].setMultipleSelect(true);
			this.menuSet[j].setKind(this.type[i]);
			this.assign(this.type[i],this.menuSet[j]);
			for (var k=0;k<this.menuSet[j].depent.length;k++){
				if (i==0)
					this.menuSet[j].depent[k].setMultipleSelect(null);
				else
					this.menuSet[j].depent[k].setMultipleSelect(true);
			}
		}
	}
	this.menuSet[j].change();
	return(this.radioSet[j]);*/
	var j=this.getElement(this.radioSet,radio);
	if (index==0)
		this.menuSet[j].setMultipleSelect(null);
	else
		this.menuSet[j].setMultipleSelect(true);
	this.menuSet[j].setKind(this.type[index]);
	this.assign(this.type[index],this.menuSet[j]);
	for (var k=0;k<this.menuSet[j].depent.length;k++){
		if (index==0)
			this.menuSet[j].depent[k].setMultipleSelect(null);
		else
			this.menuSet[j].depent[k].setMultipleSelect(true);
	}
	this.menuSet[j].change();
	return(this.radioSet[j]);
}

function setRadio(){
	radios=new Array();
	states=new Array();
	numStates=0;
}
new setRadio();
setRadio.prototype.addRadio=setRadioAddRadio;
setRadio.prototype.removeRadio=setRadioRemoveRadio;
setRadio.prototype.addState=setRadioAddState;
setRadio.prototype.removeState=setRadioRemoveState;
setRadio.prototype.changeState=setRadioChangeState;

function setRadioAddRadio(radio){
	radios[radios.length]=radio;
}

function setRadioRemoveRadio(radio){
	for (var i=0;i<radios.length;i++)
		if (radios[i]==radio)
			radios.pop(i);}

function setRadioAddState(state,radio){
	states[state]=new Array();
	states[state].value=radio;
	states[state].index=numStates++;
}

function setRadioRemoveState(state){
	states.pop(state)
	numStates--
}

function setRadioChangeState(state,radio){
	var temp=states[state].value;
	for (var x in states) {
		if (states[x].value[1].name==radio[1].name){
			states[state].value=formConnector.update(states[x].value,states[state].index);
			temp[states[x].index].status=true;
			states[x].value=formConnector.update(temp,states[x].index);
			break;
		}
	}
}
