// JavaScript Document
var controlarAltosWidgetProd = function(cont){
	//return false;
	var sum = 6,offsetTop = 0;
	var i,j,alto = 0,arrDivs = new Array();
	var nom,desc;
	var arrAlto = {'nom' : 0, 'desc' : 0};
	
	for(i=0;i<cont.childNodes.length;i++){
		if(cont.childNodes[i].tagName && cont.childNodes[i].tagName.toLowerCase() == 'div'){
			arrDivs.push(cont.childNodes[i]);
			if(cont.childNodes[i].offsetHeight > alto)alto = cont.childNodes[i].offsetHeight;
		}
	}
	for(j=0;j<arrDivs.length;j++){
		arrDivs[j].style.height = (alto) + 'px';
	}
	alto = 0;
	arrDivs = new Array();
	
	for(i=0;i<cont.childNodes.length;i++){
		if(cont.childNodes[i].tagName && cont.childNodes[i].tagName.toLowerCase() == 'div'){
			if(offsetTop == 0)offsetTop = cont.childNodes[i].offsetTop;
			if(offsetTop == cont.childNodes[i].offsetTop){
				arrDivs.push(cont.childNodes[i]);
				if(cont.childNodes[i].firstChild.offsetHeight > alto)alto = cont.childNodes[i].firstChild.offsetHeight;
				
			}
			else{

				var off = 0,p;
				for(j=0;j<arrDivs.length;j++){
					arrDivs[j].firstChild.style.height = (alto + sum) + 'px';
					arrDivs[j].firstChild.style.overflow = 'hidden';
				}

				
				offsetTop = cont.childNodes[i].offsetTop;				

				arrDivs = new Array();
				arrDivs.push(cont.childNodes[i]);
				alto = cont.childNodes[i].firstChild.offsetHeight;
				
			}
		}
	}
	
	if(arrDivs.length > 0){
		var off = 0,p;
		var arrP = new Array();
		
		for(i=0;i<arrDivs.length;i++){
			arrDivs[i].firstChild.style.height = (alto + sum) + 'px';
			arrDivs[i].firstChild.style.overflow = 'hidden';			
		}
	}
	
	for(i=0;i<cont.childNodes.length;i++){
		if(cont.childNodes[i].tagName && cont.childNodes[i].tagName.toLowerCase() == 'div'){
			cont.childNodes[i].style.height = 'auto';
		}
	}
	
}
var objPageWidget = function(conf){

	this.changePage = function(pageChange,values){
		var i;
		if(pageChange)this.page = pageChange;
		var v = 'confWidget' + SEP_IGUAL + this.confWidget + SEP_AND;
		v += 'page' + SEP_IGUAL + this.page + SEP_AND;
		v += 'file' + SEP_IGUAL + this.file + SEP_AND;
		v += 'index' + SEP_IGUAL + this.index + SEP_AND;
		v += 'idElemento' + SEP_IGUAL + this.idElemento + SEP_AND;
		if(values)this.values = values;
		if(this.values)v += this.values;
		if(oConf.extras){
			for(i in oConf.extras){
				v += i + SEP_IGUAL + oConf.extras[i] + SEP_AND;
			}
		}
		this.showBlocker(true);
		loading = true;
		if (oPageWidget.checking) { window.clearTimeout(oPageWidget.checking); }	

		req.pedir(DIR_SERVER_ROOT + 'requests/cargarWidget.php',v);
	}
	
	//L
	var listener = function(){
		var d = req.respuestaXML;
		loading = false;		
		if(d){
			this.cont.innerHTML = d.firstChild.data;
			
			controlarAltosWidgetProd(this.cont);
			this.blocker.style.display = 'none';
			this.loader.style.display = 'none';

			var l = document.location;
			var v;
			if (l.href.indexOf('#!') == -1) {
				v = '&Page-' + this.index + '=1';
				l.href = l.pathname + '#!' + encodeURI(v.substr(1));				
			}
			v = '&Page-' + this.index + '=' + this.page;
			l.href = l.pathname + '#!' + encodeURI(v.substr(1));
			oPageWidget.urlCheck();
		}
		else alert(req.respuestaHTML);
		this.showBlocker();

	}.closure(this);

	//S
	this.showBlocker = function(mostrar){
		if(mostrar){
			if(!blockerInit){
				if(!this.blocker){
					this.blocker = $('wdBlocker' + oConf.index);
					this.loader = $('wdLoader' + oConf.index);
					this.cont = $('wdCont' + oConf.index);
				}
				
				blockerInit = true;
				setOpacity(70,this.blocker);
			}
			
			this.blocker.style.width = this.cont.offsetWidth + 'px';
			this.blocker.style.height = this.cont.offsetHeight + 'px';
			this.blocker.style.display = 'block';

			this.loader.style.display = 'block';
			this.loader.style.marginLeft = Math.round((this.cont.offsetWidth - this.loader.offsetWidth)/2) + 'px';
			this.loader.style.marginTop = Math.round((this.cont.offsetHeight - this.loader.offsetHeight)/2) + 'px';
			
			
		}
		else{
			this.blocker.style.display = 'none';
			this.loader.style.display = 'none';			
		}
	}

	

	this.index = conf.index;
	this.blocker = $('wdBlocker' + conf.index);
	this.loader = $('wdLoader' + conf.index);
	this.cont = $('wdCont' + conf.index);
	this.file = conf.file;
	this.idElemento = conf.idElemento;
	this.confWidget = conf.confWidget;
	var req = new Request(listener);
	var blockerInit = false;
	this.page = 1;
	var loading = false;
	var oConf = conf;
}
