/**********************************************************************
TERMS OF USE - EASING EQUATIONS
Open source under the BSD License.
Copyright (c) 2001 Robert Penner
JavaScript version copyright (C) 2006 by Philippe Maegerman
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

   * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
   * Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
   * Neither the name of the author nor the names of contributors may
be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*****************************************/
function Delegate() {}
Delegate.create = function (o, f) {
	var a = new Array() ;
	var l = arguments.length ;
	for(var i = 2 ; i < l ; i++) a[i - 2] = arguments[i] ;
	return function() {
		var aP = [].concat(arguments, a) ;
		f.apply(o, aP);
	}
}

Tween = function(obj, prop, func, begin, finish, duration, suffixe){
	this.init(obj, prop, func, begin, finish, duration, suffixe)
}
var t = Tween.prototype;

t.obj = new Object();
t.prop='';
t.func = function (t, b, c, d) { return c*t/d + b; };
t.begin = 0;
t.change = 0;
t.prevTime = 0;
t.prevPos = 0;
t.looping = false;
t._duration = 0;
t._time = 0;
t._pos = 0;
t._position = 0;
t._startTime = 0;
t._finish = 0;
t.name = '';
t.suffixe = '';
t._listeners = new Array();	
t.setTime = function(t){
	this.prevTime = this._time;
	if (t > this.getDuration()) {
		if (this.looping) {
			this.rewind (t - this._duration);
			this.update();
			this.broadcastMessage('onMotionLooped',{target:this,type:'onMotionLooped'});
		} else {
			this._time = this._duration;
			this.update();
			this.stop();
			this.broadcastMessage('onMotionFinished',{target:this,type:'onMotionFinished'});
		}
	} else if (t < 0) {
		this.rewind();
		this.update();
	} else {
		this._time = t;
		this.update();
	}
}
t.getTime = function(){
	return this._time;
}
t.setDuration = function(d){
	this._duration = (d == null || d <= 0) ? 100000 : d;
}
t.getDuration = function(){
	return this._duration;
}
t.setPosition = function(p){
	this.prevPos = this._pos;
	var a = this.suffixe != '' ? this.suffixe : '';
	this.obj[this.prop] = Math.round(p) + a;
	this._pos = p;
	this.broadcastMessage('onMotionChanged',{target:this,type:'onMotionChanged'});
}
t.getPosition = function(t){
	if (t == undefined) t = this._time;
	return this.func(t, this.begin, this.change, this._duration);
};
t.setFinish = function(f){
	this.change = f - this.begin;
};
t.geFinish = function(){
	return this.begin + this.change;
};
t.init = function(obj, prop, func, begin, finish, duration, suffixe){
	if (!arguments.length) return;
	this._listeners = new Array();
	this.addListener(this);
	if(suffixe) this.suffixe = suffixe;
	this.obj = obj;
	this.prop = prop;
	this.begin = begin;
	this._pos = begin;
	this.setDuration(duration);
	if (func!=null && func!='') {
		this.func = func;
	}
	this.setFinish(finish);
}
t.start = function(){
	this.rewind();
	this.startEnterFrame();
	this.broadcastMessage('onMotionStarted',{target:this,type:'onMotionStarted'});
	//alert('in');
}
t.rewind = function(t){
	this.stop();
	this._time = (t == undefined) ? 0 : t;
	this.fixTime();
	this.update();
}
t.fforward = function(){
	this._time = this._duration;
	this.fixTime();
	this.update();
}
t.update = function(){
	this.setPosition(this.getPosition(this._time));
	}
t.startEnterFrame = function(){
	this.stopEnterFrame();
	this.isPlaying = true;
	this.onEnterFrame();
}
t.onEnterFrame = function(){
	if(this.isPlaying) {
		this.nextFrame();
		setTimeout(Delegate.create(this, this.onEnterFrame), 0);
	}
}
t.nextFrame = function(){
	this.setTime((this.getTimer() - this._startTime) / 1000);
	}
t.stop = function(){
	this.stopEnterFrame();
	this.broadcastMessage('onMotionStopped',{target:this,type:'onMotionStopped'});
}
t.stopEnterFrame = function(){
	this.isPlaying = false;
}

t.continueTo = function(finish, duration){
	this.begin = this._pos;
	this.setFinish(finish);
	if (this._duration != undefined)
		this.setDuration(duration);
	this.start();
}
t.resume = function(){
	this.fixTime();
	this.startEnterFrame();
	this.broadcastMessage('onMotionResumed',{target:this,type:'onMotionResumed'});
}
t.yoyo = function (){
	this.continueTo(this.begin,this._time);
}

t.addListener = function(o){
	this.removeListener (o);
	return this._listeners.push(o);
}
t.removeListener = function(o){
	var a = this._listeners;	
	var i = a.length;
	while (i--) {
		if (a[i] == o) {
			a.splice (i, 1);
			return true;
		}
	}
	return false;
}
t.broadcastMessage = function(){
	var arr = new Array();
	for(var i = 0; i < arguments.length; i++){
		arr.push(arguments[i])
	}
	var e = arr.shift();
	var a = this._listeners;
	var l = a.length;
	for (var i=0; i<l; i++){
		if(a[i][e])
		a[i][e].apply(a[i], arr);
	}
}
t.fixTime = function(){
	this._startTime = this.getTimer() - this._time * 1000;
}
t.getTimer = function(){
	return new Date().getTime() - this._time;
}
Tween.backEaseIn = function(t,b,c,d,a,p){
	if (s == undefined) var s = 1.70158;
	return c*(t/=d)*t*((s+1)*t - s) + b;
}
Tween.backEaseOut = function(t,b,c,d,a,p){
	if (s == undefined) var s = 1.70158;
	return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
}
Tween.backEaseInOut = function(t,b,c,d,a,p){
	if (s == undefined) var s = 1.70158; 
	if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
	return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
}
Tween.elasticEaseIn = function(t,b,c,d,a,p){
		if (t==0) return b;  
		if ((t/=d)==1) return b+c;  
		if (!p) p=d*.3;
		if (!a || a < Math.abs(c)) {
			a=c; var s=p/4;
		}
		else 
			var s = p/(2*Math.PI) * Math.asin (c/a);
		
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	
}
Tween.elasticEaseOut = function (t,b,c,d,a,p){
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (!a || a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return (a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b);
	}
Tween.elasticEaseInOut = function (t,b,c,d,a,p){
	if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) var p=d*(.3*1.5);
	if (!a || a < Math.abs(c)) {var a=c; var s=p/4; }
	else var s = p/(2*Math.PI) * Math.asin (c/a);
	if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
}

Tween.bounceEaseOut = function(t,b,c,d){
	if ((t/=d) < (1/2.75)) {
		return c*(7.5625*t*t) + b;
	} else if (t < (2/2.75)) {
		return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
	} else if (t < (2.5/2.75)) {
		return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
	} else {
		return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
	}
}
Tween.bounceEaseIn = function(t,b,c,d){
	return c - Tween.bounceEaseOut (d-t, 0, c, d) + b;
	}
Tween.bounceEaseInOut = function(t,b,c,d){
	if (t < d/2) return Tween.bounceEaseIn (t*2, 0, c, d) * .5 + b;
	else return Tween.bounceEaseOut (t*2-d, 0, c, d) * .5 + c*.5 + b;
	}

Tween.strongEaseInOut = function(t,b,c,d){
	return c*(t/=d)*t*t*t*t + b;
	}

Tween.regularEaseIn = function(t,b,c,d){
	return c*(t/=d)*t + b;
	}
Tween.regularEaseOut = function(t,b,c,d){
	return -c *(t/=d)*(t-2) + b;
	}

Tween.regularEaseInOut = function(t,b,c,d){
	if ((t/=d/2) < 1) return c/2*t*t + b;
	return -c/2 * ((--t)*(t-2) - 1) + b;
	}
Tween.strongEaseIn = function(t,b,c,d){
	return c*(t/=d)*t*t*t*t + b;
	}
Tween.strongEaseOut = function(t,b,c,d){
	return c*((t=t/d-1)*t*t*t*t + 1) + b;
	}

Tween.strongEaseInOut = function(t,b,c,d){
	if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
	return c/2*((t-=2)*t*t*t*t + 2) + b;
	}/**********************************************************************
TERMS OF USE - EASING EQUATIONS
Open source under the BSD License.
Copyright (c) 2001 Robert Penner
JavaScript version copyright (C) 2006 by Philippe Maegerman
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

   * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
   * Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
   * Neither the name of the author nor the names of contributors may
be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*****************************************/
ColorTween.prototype = new Tween();
ColorTween.prototype.constructor = Tween;
ColorTween.superclass = Tween.prototype;

function ColorTween(obj,prop,func,fromColor,toColor,duration){
	this.targetObject = obj;
	this.targetProperty = prop;	
	this.fromColor = fromColor;
	this.toColor = toColor;
	this.init(new Object(),'x',func,0,100,duration);
	this.listenerObj = new Object();
	this.listenerObj.onMotionChanged = Delegate.create(this,this.onColorChanged);
	this.addListener(this.listenerObj);
}
var o = ColorTween.prototype;
o.targetObject = {};
o.targetProperty = {};
o.fromColor = '';
o.toColor = '';
o.currentColor = '';
o.listenerObj = {};
o.onColorChanged = function(){
	this.currentColor = this.getColor(this.fromColor,this.toColor,this._pos);
	this.targetObject[this.targetProperty] = this.currentColor;
}

/***********************************************
*
* Function    : getColor
*
* Parameters  :    start - the start color (in the form "RRGGBB" e.g. "FF00AC")
*            end - the end color (in the form "RRGGBB" e.g. "FF00AC")
*            percent - the percent (0-100) of the fade between start & end
*
* returns      : color in the form "#RRGGBB" e.g. "#FA13CE"
*
* Description : This is a utility function. Given a start and end color and
*            a percentage fade it returns a color in between the 2 colors
*
* Author      : www.JavaScript-FX.com
*
*************************************************/ 
o.getColor = function(start, end, percent)
{
	var r1=this.hex2dec(start.slice(0,2));
    var g1=this.hex2dec(start.slice(2,4));
    var b1=this.hex2dec(start.slice(4,6));

    var r2=this.hex2dec(end.slice(0,2));
    var g2=this.hex2dec(end.slice(2,4));
    var b2=this.hex2dec(end.slice(4,6));

    var pc = percent/100;

    r= Math.floor(r1+(pc*(r2-r1)) + .5);
    g= Math.floor(g1+(pc*(g2-g1)) + .5);
    b= Math.floor(b1+(pc*(b2-b1)) + .5);

    return("#" + this.dec2hex(r) + this.dec2hex(g) + this.dec2hex(b));
}
/*** These are the simplest HEX/DEC conversion routines I could come up with ***/
/*** I have seen a lot of fade routines that seem to make this a             ***/
/*** very complex task. I am sure somene else must've had this idea          ***/
/************************************************/  

o.dec2hex = function(dec){return(this.hexDigit[dec>>4]+this.hexDigit[dec&15]);}
o.hexDigit=new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F");
o.hex2dec = function(hex){return(parseInt(hex,16))};	
	
	var curSolAct;
	setActSol = function(evt, ele, cont){
		if(evt){ StopEvent(evt); }
		if(!!curSolAct){
			curSolAct.ele.className = '';
			curSolAct.cont.style.display = 'none';
		}
		
		curSolAct = {ele: ele, cont: cont};
		curSolAct.ele.className = 'on';
		curSolAct.cont.style.display = 'block';
	}
	
	//
	var erEmail = RegExp('^[a-z0-9_\.\-]+@[a-z0-9_\-]+(\.[a-z0-9_\-]{2,5})*\.[a-z]{2,4}$');
	var erNumero = RegExp('^[0-9]+$');
	var erFecha = RegExp('^(0[1-9]|[1-2][0-9]|3[0-1])/(0[1-9]|1[0-2])/[1-2][0-9]{3}$');
	var erSiNo = RegExp('^[01]$');
	var errorClass = 'fieldsetError';
	
	
	//
    var oClasificados = new function(){
		//
		var arrClasActSol = new Array;
		this.setClasActSol = function(id, type, plus, evt){
			if (!!evt) { StopEvent(evt); }
			if(!arrClasActSol[id]){
				arrClasActSol[id] = {};
				arrClasActSol[id][plus] = {};
			}
			else if(!arrClasActSol[id][plus]){
				arrClasActSol[id][plus] = {};
			}
			else if(!!arrClasActSol[id][plus].ele){
				
				arrClasActSol[id][plus].ele.className = '';
				arrClasActSol[id][plus].cont.style.display = 'none';
				if(arrClasActSol[id][plus].type == type){
					arrClasActSol[id][plus].type = '';
					this.fixGMapsPos();
					return false;
				}
			}
			
			arrClasActSol[id][plus].ele = $('solapa'+type+id+plus);
			arrClasActSol[id][plus].cont = $('solapa'+type+'Cont'+id+plus);
			arrClasActSol[id][plus].type = type;
			
			arrClasActSol[id][plus].ele.className = 'on';
			arrClasActSol[id][plus].cont.style.display = 'block';
			
			if(type !== 'Info'){ loadClasInfo(id, type, plus); }
			this.fixGMapsPos();
		}
		this.removeClasActSol = function(id, plus){
			if(!!arrClasActSol[id] && !!arrClasActSol[id][plus]){
				delete(arrClasActSol[id][plus]);
			}
		}
		this.unsetClasActSol = function(id, type, plus){
			if(!!arrClasActSol[id] && !!arrClasActSol[id][plus] && !!arrClasActSol[id][plus]['loaded'+type]){
				this.setClasActSol(id, type, plus);
				delete(arrClasActSol[id][plus]['loaded'+type]);
				if(id == idClasificado){ idClasificado = 0; }
			}
		}
		
		
		//
		var clasInfo;
		var wait = false, reqType;
		var req = new Request();
		var textLoading = '<div style="text-align:center; padding:30px 0;">' +
		'<img src="' + DIR_ROOT + 'img/loader.gif" /><br />Cargando...</div>';
		
		//
		var loadClasInfo = function(id, type, plus){
			//
			if(arrClasActSol[id][plus]['loading'+type] !== true){
				arrClasActSol[id][plus].cont.innerHTML = textLoading;
				arrClasActSol[id][plus]['loading'+type] = true;
			}
			
			if(wait || arrClasActSol[id][plus]['loaded'+type] === true){ return false; }
			
			wait = true;
			clasInfo = {id: id, type: type, plus: plus};
			reqType = 'info';
			
			var v = 'idClasificado' + SEP_IGUAL + id + SEP_AND;
			v += 'idPlus' + SEP_IGUAL + plus + SEP_AND;
			v += 'idIdioma' + SEP_IGUAL + ID_IDIOMA + SEP_AND;
			v += 'idRubro' + SEP_IGUAL + ID_RUBRO + SEP_AND;
			v += 'tipo' + SEP_IGUAL + type.toLowerCase() + SEP_AND;
			v += 'tabindex' + SEP_IGUAL + consultaTabIndex + SEP_AND;
			v += respuestas;
			v += datosPersonales;
			
			req.pedir(DIR_ROOT + 'requests/clasificadosInfo.php', v);
		}
		
		
		//
		req.listener = function(){
			var d = req.respuestaXML;
			wait = false;
			
			if(!d){ ; }//alert(req.respuestaHTML); }
			//
			else if(reqType == 'info'){
				arrClasActSol[clasInfo.id][clasInfo.plus].cont.innerHTML = d.firstChild.data;
				arrClasActSol[clasInfo.id][clasInfo.plus]['loaded'+clasInfo.type] = true;
				
				if(clasInfo.type == 'Localizar'){
					var ele = $('mapaScript'+clasInfo.id+clasInfo.plus);
					eval($('mapaScript'+clasInfo.id+clasInfo.plus)[(Nav.esIE)? 'innerText' : 'textContent']);
					mapas[clasInfo.id] = $('mapaCont'+clasInfo.id+clasInfo.plus);
				}
				else if(clasInfo.type == 'Consultar'){
					inicializarConsulta(clasInfo.id, clasInfo.plus);
				}
			}
			//
			else if(reqType == 'consultar'){
				
				cargandoR.style.display = 'none';
				nombreR.disabled = apellidoR.disabled = emailR.disabled = comentarioR.disabled = 
				cpR.value = direccionR.disabled = telefonoR.disabled = ciudadR.value = 
				provinciaR.value = false;
				
				if(d.getAttribute('exito') != 'si'){
					
					errorR.innerHTML = d.firstChild.data;
					errorR.style.display = 'block';
				}
				else{
					/*nombreR.value = apellidoR.value = emailR.value = comentarioR.value = 
					direccionR.value = ciudadR.value = 
					provinciaR.value = telefonoR.value = cpR.value = '';
					
					limpiarPreguntas();
					
					exitoR.innerHTML = d.firstChild.data;
					exitoR.style.display = 'block';*/
					//
					arrClasActSol[clasInfo.id][clasInfo.plus].cont.innerHTML = d.firstChild.data;
					try { $('solapaConsultar'+clasInfo.id+clasInfo.plus).firstChild.focus(); }
					catch(e){}
				}
			}
			//
			else if(reqType == 'actualizar'){
				$('clasificadosCont').innerHTML = d.firstChild.data;
				setActSol(false, $('solapaDirectorio'), $('directorio'));
				blinkTitle();
			}
			//
			else if(reqType == 'provincias'){
				
				while(provinciaR.hasChildNodes()){ provinciaR.removeChild(provinciaR.firstChild); }
				
				for(var i = 0, t = d.childNodes.length; i < t; i++){
					var opt = document.createElement('option');
					opt.value = d.childNodes[i].getAttribute('value');
					opt.innerHTML = d.childNodes[i].firstChild.data;
					
					provinciaR.appendChild(opt);
				}
				provinciaR.disabled = false;
			}
			//
			else if(reqType == 'ciudades'){
				
				while(ciudadR.hasChildNodes()){ ciudadR.removeChild(ciudadR.firstChild); }
				
				for(var i = 0, t = d.childNodes.length; i < t; i++){
					var opt = document.createElement('option');
					opt.value = d.childNodes[i].getAttribute('value');
					opt.innerHTML = d.childNodes[i].firstChild.data;
					
					ciudadR.appendChild(opt);
				}
				ciudadR.disabled = false;
			}
			//
			else if(reqType == 'barrios'){
				
				while(barrioR.hasChildNodes()){ barrioR.removeChild(barrioR.firstChild); }
				
				for(var i = 0, t = d.childNodes.length; i < t; i++){
					var opt = document.createElement('option');
					opt.value = d.childNodes[i].getAttribute('value');
					opt.innerHTML = d.childNodes[i].firstChild.data;
					
					barrioR.appendChild(opt);
				}
				barrioR.disabled = false;
			}
			//
			this.fixGMapsPos();
		}.closure(this);
		
		
		//
		var mapas = new Object;
		this.fixGMapsPos = function(){
			if(Nav.esIE){ 
				for(var i in mapas){
					mapas[i].style.position = 'static';
					mapas[i].style.position = 'relative';
				}
			}
		}
		
		
		// Envio de Consulta del Clasificado
		var datosPersonales = (Cookie.get('datosPersonales') == '')? '' : Cookie.get('datosPersonales');
		var idClasificado, idPlus, nombreR, apellidoR, emailR, comentarioR, paisR, provinciaR, provinciaNR, 
		ciudadR, ciudadNR, barrioR, barrioNR, direccionR, cpR, telefonoR, errorR, cargandoR, exitoR;
		
		var consultaTabIndex = 0;
		this.consultar = function(evt, id, plus){
			var error = false, t = '';
			
			if(evt){ StopEvent(evt); }
			if(wait){ return false; }
			
			inicializarConsulta(id, plus);
			
			//exitoR.style.display = 'none';
			nombreR.onblur();
			if(nombreR.parentNode.className == errorClass){ error = true; }
			
			apellidoR.onblur();
			if(apellidoR.parentNode.className == errorClass){ error = true; }
			
			emailR.onblur();
			if(emailR.parentNode.className == errorClass){ error = true; }
			
			provinciaR.onblur();
			if(provinciaR.parentNode.className == errorClass){ error = true; }
			
			ciudadR.onblur();
			if(ciudadR.parentNode.className == errorClass){ error = true; }
			
			barrioR.onblur();
			if(barrioR.parentNode.className == errorClass){ error = true; }
			
			telefonoR.onblur();
			if(telefonoR.parentNode.className == errorClass){ error = true; }
			
			//
			if(!validarPreguntas()){ error = true; }
			
			apellidoR.disabled = nombreR.disabled = emailR.disabled = comentarioR.disabled = 
			cpR.disabled = direccionR.disabled = telefonoR.disabled = (error)? false : true;
			
			if(error){
				errorR.innerHTML = 'Complete o corrija los campos resaltados';
				errorR.style.display = 'block';
				return false;
			}
			
			errorR.style.display = 'none';
			cargandoR.style.display = 'block';
			
			wait = true;
			reqType = 'consultar';
			clasInfo = {id: id, plus: plus};
			
			t += getDatosPersonales();
			t += 'idClasificado' + SEP_IGUAL + idClasificado + SEP_AND;
			t += 'idIdioma' + SEP_IGUAL + ID_IDIOMA + SEP_AND;
			t += 'idRubro' + SEP_IGUAL + ID_RUBRO + SEP_AND;
			t += 'idPlus' + SEP_IGUAL + idPlus + SEP_AND;
			t += 'comentario' + SEP_IGUAL + comentarioR.value + SEP_AND;
			t += respuestas;
			
			req.pedir(DIR_ROOT + 'requests/consultarClasificado.php', t);
		}
		var inicializarConsulta = function(id, plus){
			if(id != idClasificado || plus != idPlus){
				
				consultaTabIndex++;
				
				nombreR = $('nombreRecomendar'+id+plus);
				if(!nombreR.onblur){
					nombreR.onblur = function(){
						var v = trim(this.value);
						if(v == '' || v.length < 3){ this.parentNode.className = errorClass; }
						else{ this.parentNode.className = ''; }
					}.closure(nombreR);
				}
				
				apellidoR = $('apellidoRecomendar'+id+plus);
				if(!apellidoR.onblur){
					apellidoR.onblur = function(){
						var v = trim(this.value);
						if(v == '' || v.length < 3){ this.parentNode.className = errorClass; }
						else{ this.parentNode.className = ''; }
					}.closure(apellidoR);
				}
				
				emailR = $('emailRecomendar'+id+plus);
				if(!emailR.onblur){
					emailR.onblur = function(){
						var v = trim(this.value);
						if(v == '' || !erEmail.test(v)){ this.parentNode.className = errorClass; }
						else{ this.parentNode.className = ''; }
					}.closure(emailR);
				}
				
				paisR = $('paisRecomendar'+id+plus);
				if(!paisR.onchange){
					paisR.onchange = function(){
						provinciaR.disabled = ciudadR.disabled =
						barrioR.disabled = true;
						
						provinciaNR.style.display = ciudadNR.style.display = 
						barrioNR.style.display = 'none';
						
						reqType = 'provincias';
						
						var v = 'tipo' + SEP_IGUAL + reqType + SEP_AND;
						v += 'idPais' + SEP_IGUAL + paisR.value + SEP_AND;
						
						req.pedir(DIR_ROOT + 'requests/zonas_geograficas.php', v);
					};
				}
				
				provinciaR = $('provinciaRecomendar'+id+plus);
				if(!provinciaR.onchange){
					provinciaR.onchange = function(){
						
						var v = trim(provinciaR.value);
						
						ciudadR.disabled = barrioR.disabled = true;
						provinciaNR.style.display = (v == '0')? '' : 'none';
						ciudadNR.style.display = barrioNR.style.display = 'none';
						
						if(erNumero.test(v) && v != ''){
							
							reqType = 'ciudades';
							
							var v = 'tipo' + SEP_IGUAL + reqType + SEP_AND;
							v += 'idProvincia' + SEP_IGUAL + provinciaR.value + SEP_AND;
							
							req.pedir(DIR_ROOT + 'requests/zonas_geograficas.php', v);
						}
					};
				}
				if(!provinciaR.onblur){
					provinciaR.onblur = function(){
						var v = trim(this.value);
						if(v == '' || !erNumero.test(v)){ this.parentNode.className = errorClass; }
						else{ provinciaNR.onblur(); }
					}.closure(provinciaR);
				}
				
				provinciaNR = $('provinciaNombreRecomendar'+id+plus);
				if(!provinciaNR.onblur){
					provinciaNR.onblur = function(){
						var v = trim(this.value);
						if(provinciaR.value == '0' && (v == '' || v.length < 3)){ this.parentNode.className = errorClass; }
						else{ this.parentNode.className = ''; }
					}.closure(provinciaNR);
				}
				
				ciudadR = $('ciudadRecomendar'+id+plus);
				if(!ciudadR.onchange){
					ciudadR.onchange = function(){
						
						var v = trim(ciudadR.value);
						
						barrioR.disabled = true;
						ciudadNR.style.display = (v == '0')? '' : 'none';
						barrioNR.style.display = 'none';
						
						if(erNumero.test(v) && v != ''){
							
							reqType = 'barrios';
							
							var v = 'tipo' + SEP_IGUAL + reqType + SEP_AND;
							v += 'idCiudad' + SEP_IGUAL + ciudadR.value + SEP_AND;
							
							req.pedir(DIR_ROOT + 'requests/zonas_geograficas.php', v);
						}
					};
				}
				if(!ciudadR.onblur){
					ciudadR.onblur = function(){
						var v = trim(this.value);
						if(v == '' || !erNumero.test(v)){ this.parentNode.className = errorClass; }
						else{ ciudadNR.onblur(); }
					}.closure(ciudadR);
				}
				
				ciudadNR = $('ciudadNombreRecomendar'+id+plus);
				if(!ciudadNR.onblur){
					ciudadNR.onblur = function(){
						var v = trim(this.value);
						if(ciudadR.value == '0' && (v == '' || v.length < 3)){ this.parentNode.className = errorClass; }
						else{ this.parentNode.className = ''; }
					}.closure(ciudadNR);
				}
				
				barrioR = $('barrioRecomendar'+id+plus);
				if(!barrioR.onchange){
					barrioR.onchange = function(){
						
						var v = trim(barrioR.value);
						barrioNR.style.display = (v == '0')? '' : 'none';
					};
				}
				if(!barrioR.onblur){
					barrioR.onblur = function(){
						var v = trim(this.value);
						if(v == '' || !erNumero.test(v)){ this.parentNode.className = errorClass; }
						else{ barrioNR.onblur(); }
					}.closure(barrioR);
				}
				
				barrioNR = $('barrioNombreRecomendar'+id+plus);
				if(!barrioNR.onblur){
					barrioNR.onblur = function(){
						var v = trim(this.value);
						if(barrioR.value == '0' && (v == '' || v.length < 3)){ this.parentNode.className = errorClass; }
						else{ this.parentNode.className = ''; }
					}.closure(barrioNR);
				}
				
				telefonoR = $('telefonoRecomendar'+id+plus);
				if(!telefonoR.onblur){
					telefonoR.onblur = function(){
						var v = trim(this.value);
						if(v == '' || v.length < 7){ this.parentNode.className = errorClass; }
						else{ this.parentNode.className = ''; }
					}.closure(telefonoR);
				}
				
				direccionR = $('direccionRecomendar'+id+plus);
				cpR = $('cpRecomendar'+id+plus);
				comentarioR = $('comentarioRecomendar'+id+plus);
				errorR = $('errorRecomendar'+id+plus);
				cargandoR = $('cargandoRecomendar'+id+plus);
				//exitoR = $('exitoRecomendar'+id+plus);
				
				idClasificado = id;
				idPlus = plus;
				
				//
				inicializarPreguntas();
			}
		}
		var getDatosPersonales = function(){
			datosPersonales = '';
			datosPersonales += 'nombre' + SEP_IGUAL + trim(nombreR.value) + SEP_AND;
			datosPersonales += 'apellido' + SEP_IGUAL + trim(apellidoR.value) + SEP_AND;
			datosPersonales += 'email' + SEP_IGUAL + trim(emailR.value) + SEP_AND;
			datosPersonales += 'idPais' + SEP_IGUAL + trim(paisR.value) + SEP_AND;
			datosPersonales += 'idProvincia' + SEP_IGUAL + trim(provinciaR.value) + SEP_AND;
			datosPersonales += 'idCiudad' + SEP_IGUAL + trim(ciudadR.value) + SEP_AND;
			datosPersonales += 'idBarrio' + SEP_IGUAL + trim(barrioR.value) + SEP_AND;
			datosPersonales += 'nombreProvincia' + SEP_IGUAL + trim(provinciaNR.value) + SEP_AND;
			datosPersonales += 'nombreCiudad' + SEP_IGUAL + trim(ciudadNR.value) + SEP_AND;
			datosPersonales += 'nombreBarrio' + SEP_IGUAL + trim(barrioNR.value) + SEP_AND;
			datosPersonales += 'direccion' + SEP_IGUAL + trim(direccionR.value) + SEP_AND;
			datosPersonales += 'cp' + SEP_IGUAL + trim(cpR.value) + SEP_AND;
			datosPersonales += 'telefono' + SEP_IGUAL + trim(telefonoR.value) + SEP_AND;
			
			Cookie.set('datosPersonales', datosPersonales);
			return datosPersonales;
		}
		
		
		// Validacion de Preguntas del Clasificado
		var preguntas, respuestas = (Cookie.get('respuestas') == '')? '' : Cookie.get('respuestas');
		this.setPreguntaRespuesta = function(id, ele){
			var input = $(id);
			
			if(ele.type == 'checkbox'){
				
				if(input.value == ''){ input.value = input.idsEles = ','; }
				
				if(ele.checked){
					input.value += ele.value + ',';
					input.idsEles += ele.id + ',';
				}
				else{
					input.value = input.value.replace(',' + ele.value + ',', ',');
					input.idsEles = input.idsEles.replace(',' + ele.id + ',', ',');
				}
				
				if(input.value == ','){ input.value = input.idsEles = ''; }
			}
			else if(ele.type == 'radio' && ele.checked){
				input.value = ele.value;
				input.idEle = ele.id;
			}
			if(!!input.onblur){ input.onblur(); }
		}
		this.blurPreguntaRespuesta = function(id){
			var input = $(id);
			if(!!input.onblur){ input.onblur(); }
		}
		var inicializarPreguntas = function(){
			//
			preguntas = new Array;
			var ids = $('preguntasRecomendar'+idClasificado+idPlus);
			if(ids.value == ''){ return false; }
			
			ids = ids.value.split(',');
			for(var i = 0, t = ids.length; i < t; i++){
				
				var input = $('preguntaRecomendar'+ids[i]+'-'+idClasificado+idPlus);
				if(!input.onblur){
					
					if(input.getAttribute('requerido') == 'si'){
						input.onblur = function(){
							if(this.value == '' || 
							  (this.getAttribute('tipo') == 'numero' && !erNumero.test(this.value)) ||
							  (this.getAttribute('tipo') == 'fecha' && !erFecha.test(this.value)) ||
							  (this.getAttribute('tipo') == 'sino' && !erSiNo.test(this.value))
							){ this.parentNode.className = errorClass; }
							else{ this.parentNode.className = ''; }
						}
					}
					else if(input.getAttribute('tipo') == 'numero'){
						input.onblur = function(){
							if(this.value == '' || !erNumero.test(this.value)){ this.parentNode.className = errorClass; }
							else{ this.parentNode.className = ''; }
						}
					}
					else if(input.getAttribute('tipo') == 'fecha'){
						input.onblur = function(){
							if(this.value == '' || !erFecha.test(this.value)){ this.parentNode.className = errorClass; }
							else{ this.parentNode.className = ''; }
						}
					}
					else if(input.getAttribute('tipo') == 'sino'){
						input.onblur = function(){
							if(this.value == '' || !erSiNo.test(this.value)){ this.parentNode.className = errorClass; }
							else{ this.parentNode.className = ''; }
						}
					}
				}
				
				preguntas.push(input);
			}
		}
		var validarPreguntas = function(){
			var vale = true;
			respuestas = '';
			
			for(var i = 0, t = preguntas.length; i < t; i++){
				var input = preguntas[i];
				
				if(!!input.onblur){
					input.onblur();
					if(input.parentNode.className == errorClass){ vale = true; }
				}
				respuestas += input.name + SEP_IGUAL + trim(input.value) + SEP_AND;
			}
			
			Cookie.set('respuestas', respuestas);
			return vale;
		}
		var limpiarPreguntas = function(){
			for(var i = 0, ti = preguntas.length; i < ti; i++){
				var input = preguntas[i];
				var tipo = input.getAttribute('tipo');
				
				if(tipo == 'select'){ input.options[0].selected = true; }
				else if(input.value != ''){
					if(tipo == 'radio' || tipo == 'sino'){
						$(input.idEle).checked = false;
						input.idEle = '';
					}
					else if(tipo == 'checkbox'){
						var ids = input.idsEles.substr(1, input.idsEles.length - 2).split(',');
						for(var x = 0, tx = ids.length; x < tx; x++){ $(ids[x]).checked = false; }
						input.idsEles = '';
					}
					input.value = '';
				}
			}
		}
		
		
		// Filtrar Sub-Rubros
		var categorias = new Object;
		this.addCategoria = function(evt, cat){
			if(evt){ StopEvent(evt); }
			if(wait || !!categorias[cat.id]){ return false; }
			
			categorias[cat.id] = cat.name;
			this.changePage(false, 1);
		}
		this.remCategoria = function(evt, cat){
			if(evt){ StopEvent(evt); }
			if(wait || !categorias[cat]){ return false; }
			
			delete categorias[cat];
			this.changePage(false, 1);
		}
		
		
		// Filtrar Ciudades
		var ciudades = new Object;
		this.addCiudad = function(evt, ciu){
			if(evt){ StopEvent(evt); }
			if(wait || !!ciudades[ciu.id]){ return false; }
			
			ciudades[ciu.id] = ciu.name;
			this.changePage(false, 1);
		}
		this.remCiudad = function(evt, ciu){
			if(evt){ StopEvent(evt); }
			if(wait || !ciudades[ciu]){ return false; }
			
			delete ciudades[ciu];
			this.changePage(false, 1);
		}
		
		
		// Cambiar de Pagina
		var pagina = 1;
		this.changePage = function(evt, page, stopScroll){
			if(evt){ StopEvent(evt); }
			pagina = page;
			
			actualizar();
			if(!stopScroll){ scrollToTop(); }
		}
		
		
		// Animaciones
		var scrollOnTop = true;
		var scrollToTop = function(){
			var t = new Tween(document.documentElement, 'scrollTop', Tween.strongEaseOut, document.documentElement.scrollTop, 240, 1, '');
			t.onMotionFinished = function(){
				scrollOnTop = true;
				blinkTitle();
			}
			scrollOnTop = false;
			t.start();
		}
		var blinkTitle = function(){
			var tit = $('directorioTituloPagina');
			if(scrollOnTop && !wait && !!tit){
				var t = new ColorTween(tit.style, 'color', Tween.bounceEaseOut, 'FFFFFF', COLORB, 2);
				t.onMotionFinished = function(){
					var t = new ColorTween(tit.style, 'color', Tween.strongEaseOut, COLORB, 'FFFFFF', 2);
					t.start();
				}
				t.start();
			}
		}
		
		
		// Recargar
		var actualizar = function(){
			var v, i, ids, names;
			
			wait = true;
			reqType = 'actualizar';
			
			v = 'idRubro' + SEP_IGUAL + ID_RUBRO + SEP_AND;
			v += 'nomRubro' + SEP_IGUAL + NOMBRE_RUBRO + SEP_AND;
			v += 'idioma' + SEP_IGUAL + ID_IDIOMA + SEP_AND;
			v += 'pagina' + SEP_IGUAL + pagina + SEP_AND;
			
			ids = names = '';
			for(i in categorias){
				ids += i + ',';
				names += categorias[i] + ',';
			}
			if(ids != ''){
				v += 'idsCategorias' + SEP_IGUAL + ids + SEP_AND;
				v += 'namesCategorias' + SEP_IGUAL + names + SEP_AND;
			}
			
			ids = names = '';
			for(i in ciudades){
				ids += i + ',';
				names += ciudades[i] + ',';
			}
			if(ids != ''){
				v += 'idsCiudades' + SEP_IGUAL + ids + SEP_AND;
				v += 'namesCiudades' + SEP_IGUAL + names + SEP_AND;
			}
			
			v += 'idsClasificados' + SEP_IGUAL + oPresupuesto.getClasificados() + SEP_AND;
			
			$('clasificadosCont').innerHTML = textLoading;
			
			arrClasActSol = new Array;
			oPresupuesto.unload();
			
			req.pedir(DIR_ROOT + 'requests/directorio.php', v);
		}
		
		
		// Boton Agregar al Presupuesto
		this.addClasificado = function(evt, ele, id){
			var idRubro = ID_RUBRO;
			if(ele.className == 'btnPresupuesto' || ele.className == 'btnPresupuestoChico'){
				ele.className += 'Ok';
				ele.onmouseover = function (evt){ oTooltip.mostrar(evt, 'Quitar del presupuesto', 'ToolTipMsgNormal'); };
				oTooltip.ocultar();
				ele.onmouseover(evt);
				
				oPresupuesto.addRubro(evt, {checked: true}, idRubro);
				oPresupuesto.addClasificado(false, idRubro, id);
			}
			else{
				ele.className = ele.className.substring(0, ele.className.length - 2);
				ele.onmouseover = function (evt){ oTooltip.mostrar(evt, 'Agregar al presupuesto', 'ToolTipMsgNormal'); };
				oTooltip.ocultar();
				ele.onmouseover(evt);
				
				oPresupuesto.removeClasificado(false, false, idRubro, id);
			}
			if(oPresupuesto.getStep() > 0){ oPresupuesto.loadStep(false, oPresupuesto.getStep(), true, true); }
			
			var sol = $('solapaPresupuesto');
			var t = new ColorTween(sol.firstChild.style, 'backgroundColor', Tween.bounceEaseOut, 'F9F9F9', COLORB, 2);
			t.onMotionFinished = function(){
				var t = new ColorTween(sol.firstChild.style, 'backgroundColor', Tween.strongEaseOut, COLORB, 'F9F9F9', 2);
				t.onMotionFinished = function(){
					sol.firstChild.style.backgroundColor = '';
				}
				t.start();
			}
			t.start();
		}
	}
	
	
	////////////////////////////////////////////////
	
	
	//
	var oPresupuesto = new function(){
		
		var wait = false, reqType;
		var req = new Request();
		var textLoading = '<div style="text-align:center; padding:30px 0;">' +
		'<img src="' + DIR_ROOT + 'img/loader.gif" /><br />Cargando...</div>';
		
		req.listener = function(){
			var d = req.respuestaXML;
			wait = false;
			loaded = true;
			
			if(!d){ ; }//alert(req.respuestaHTML); }
			//
			else if(reqType == 'pasos'){
				$('presupuesto').innerHTML = d.firstChild.data;
				
				totalRubrosElegidos = parseInt(d.lastChild.getAttribute('totalRubrosElegidos'));
				totalClasificadosElegidos = parseInt(d.lastChild.getAttribute('totalClasificadosElegidos'));
				if(paso == 3 && d.getAttribute('tipo') != 'error'){ inicializarConsulta(); }
			}
			//
			else if(reqType == 'clasificados'){
				$('layPresupuestoCont').innerHTML = d.firstChild.data;
				
				if(!stopLayMove){
					var lay = $('layPresupuesto');
					var pos = (((document.documentElement.clientHeight - lay.offsetHeight) / 2 ) + document.documentElement.scrollTop);
					if(pos < 5){ pos = 5; }
					lay.style.top = pos + 'px';
					lay.style.visibility = 'visible';
				}
				
				var id, ele;
				for(id in addClasificados){
					ele = $('checkLayCasificado'+id);
					if(ele){ FireEvent(ele, 'click'); }
				}
				
				for(id in remClasificados){
					ele = $('checkLayCasificado'+id);
					if(ele){ FireEvent(ele, 'click'); }
				}
			}
			//
			else if(reqType == 'confirmar'){
				
				cargandoP.style.display = 'none';
				nombreP.disabled = emailP.disabled = provinciaP.disabled = 
				ciudadP.disabled = direccionP.disabled = telefonoP.disabled = false;
			
				if(d.getAttribute('tipo') == 'error'){
					
					errorP.innerHTML = d.firstChild.data;
					errorP.style.display = 'block';
				}
				else{
					validado = true;
					paso = 4;
					$('presupuesto').innerHTML = d.firstChild.data;
				}
			}
			//
			else if(reqType == 'verMas'){
				$('layClasificadoCont').innerHTML = d.firstChild.data;
				
				var lay = $('layClasificado');
				var pos = (((document.documentElement.clientHeight - lay.offsetHeight) / 2 ) + document.documentElement.scrollTop);
				if(pos < 5){ pos = 5; }
				lay.style.top = pos + 'px';
				lay.style.visibility = 'visible';
			}
			//
			else if(reqType == 'consultar'){
				$('presupuesto').innerHTML = d.firstChild.data;
				scrollToPos(240);
				
				if(d.getAttribute('tipo') != 'error'){
					rubros = clasificados = ',';
					validado = false;
					
					Cookie.unset('rubros');
					Cookie.unset('clasificados');
					oPresupuesto.initMiPrespuesto();
				}
			}
			//
			else if(reqType == 'provincias'){
				
				while(provinciaP.hasChildNodes()){ provinciaP.removeChild(provinciaP.firstChild); }
				
				for(var i = 0, t = d.childNodes.length; i < t; i++){
					var opt = document.createElement('option');
					opt.value = d.childNodes[i].getAttribute('value');
					opt.innerHTML = d.childNodes[i].firstChild.data;
					
					provinciaP.appendChild(opt);
				}
				provinciaP.disabled = false;
			}
			//
			else if(reqType == 'ciudades'){
				
				while(ciudadP.hasChildNodes()){ ciudadP.removeChild(ciudadP.firstChild); }
				
				for(var i = 0, t = d.childNodes.length; i < t; i++){
					var opt = document.createElement('option');
					opt.value = d.childNodes[i].getAttribute('value');
					opt.innerHTML = d.childNodes[i].firstChild.data;
					
					ciudadP.appendChild(opt);
				}
				ciudadP.disabled = false;
			}
			//
			else if(reqType == 'barrios'){
				
				while(barrioP.hasChildNodes()){ barrioP.removeChild(barrioP.firstChild); }
				
				for(var i = 0, t = d.childNodes.length; i < t; i++){
					var opt = document.createElement('option');
					opt.value = d.childNodes[i].getAttribute('value');
					opt.innerHTML = d.childNodes[i].firstChild.data;
					
					barrioP.appendChild(opt);
				}
				barrioP.disabled = false;
			}
			//
		}.closure(this);
		
		
		//
		var loaded = false;
		this.loaded = function(){
			return loaded;
		}
		this.unload = function(){
			loaded = false;
			paso = 0;
		}
		
		
		// Animacion
		var scrollOnTop = true;
		var scrollToPos = function(pos){
			var t = new Tween(document.documentElement, 'scrollTop', Tween.strongEaseOut, document.documentElement.scrollTop, pos, 1, '');
			t.onMotionFinished = function(){
				scrollOnTop = true;
			}
			scrollOnTop = false;
			t.start();
		}
		
		
		// Solapa de Pasos
		var paso = 0;
		this.loadStep = function(evt, step, forced, stopScroll){
			//
			if((wait || paso == step || !canLoadStep(step)) && !forced){ return false; }
			if(evt){ StopEvent(evt); }
			
			wait = true;
			reqType = 'pasos';
			paso = step;
			
			$('presupuesto').innerHTML = textLoading;
			
			var v = 'tipo' + SEP_IGUAL + reqType + SEP_AND;
			v += 'paso' + SEP_IGUAL + paso + SEP_AND;
			v += 'idsRubros' + SEP_IGUAL + this.getRubros() + SEP_AND;
			v += 'idsClasificados' + SEP_IGUAL + this.getClasificados() + SEP_AND;
			v += datosPersonales;
			v += respuestas;
			v += 'idIdioma' + SEP_IGUAL + ID_IDIOMA + SEP_AND;
			
			req.pedir(DIR_ROOT + 'requests/presupuesto.php', v);
			
			if(!stopScroll){ scrollToPos(240); }
		}
		this.getStep = function(){
			return paso;
		}
		
		
		// Check de Lista de Rubros
		var rubros = (Cookie.get('rubros') == '')? ',' : Cookie.get('rubros');
		this.addRubro = function(evt, ele, id){
			if(id == 0){ return false; }
			
			if(ele.checked){
				if(rubros.indexOf(',' + id + ',') == -1){
					rubros += id + ',';
					totalRubrosElegidos++;
					
					//Para que complete nuevamente el formulario
					validado = false;
				}
				if(!!ele.parentNode){ ele.parentNode.parentNode.className = 'on'; }
			}
			else{
				if(rubros.indexOf(',' + id + ',') != -1){
					rubros = rubros.replace(',' + id + ',', ',');
					totalRubrosElegidos--;
				}
				if(!!ele.parentNode){ ele.parentNode.parentNode.className = ''; }
				
				//
				var er = new RegExp(',' + id + '-[1-9][0-9]*,');
				while(er.test(clasificados)){
					clasificados = clasificados.replace(er, ',');
					totalClasificadosElegidos--;
				}
				Cookie.set('clasificados', clasificados);
			}
			Cookie.set('rubros', rubros);
			this.initMiPrespuesto();
		}
		this.getRubros = function(){
			return rubros.substr(1, rubros.length - 1);
		}
		
		
		// Botones de Agregar y Quitar Clasificado
		var clasificados = (Cookie.get('clasificados') == '')? ',' : Cookie.get('clasificados');
		this.addClasificado = function(evt, rubro, id){
			var add = false;
			if(evt){ StopEvent(evt); }
			if(rubro == 0 || id == 0){ return false; }
			
			if(clasificados.indexOf(',' + rubro + '-' + id + ',') == -1){
				clasificados += rubro + '-' + id + ',';
				totalClasificadosElegidos++;
				
				add = true;
				
				//Activamos el boton agregar a presupuesto
				if(ID_RUBRO == rubro){
					ele = $('clasficadoAddPresu'+id);
					if(!!ele){ ele.className = (ele.className == 'btnPresupuesto' || ele.className == 'btnPresupuestoOk')? 'btnPresupuestoOk' : 'btnPresupuestoChicoOk'; }
				}
			}
			if(rubros.indexOf(',' + rubro + ',') == -1){
				rubros += id + ',';
				Cookie.set('rubros', rubros);
			}
			Cookie.set('clasificados', clasificados);
			this.initMiPrespuesto();
			
			return add;
		}
		this.removeClasificado = function(evt, ele, rubro, id){
			if(evt){ StopEvent(evt); }
			
			if(clasificados.indexOf(',' + rubro + '-' + id + ',') != -1){
				clasificados = clasificados.replace(',' + rubro + '-' + id + ',', ',');
				totalClasificadosElegidos--;
			}
			
			Cookie.set('clasificados', clasificados);
			this.initMiPrespuesto();
			
			if(!!ele){ ele.parentNode.removeChild(ele); }
			
			//Desactivamos el boton agregar a presupuesto
			if(ID_RUBRO == rubro){
				ele = $('clasficadoAddPresu'+id);
				if(!!ele){ ele.className = (ele.className == 'btnPresupuesto' || ele.className == 'btnPresupuestoOk')? 'btnPresupuesto' : 'btnPresupuestoChico'; }
			}
		}
		this.getClasificados = function(){
			return clasificados.substr(1, clasificados.length - 1);
		}
		
		
		// Layer Agregar Clasificados
		var idRubro, addClasificados, remClasificados, paginaClasificados = 1, posLayClas, stopLayMove;
		this.openLayClasificados = function(evt, rubro){
			if(evt){ StopEvent(evt); }
			if(wait){ return false; }
			
			var lay = $('layPresupuestoBlock');
			setOpacity(70, lay);
			lay.style.display = 'block';
			
			lay = $('layPresupuesto');
			var pos = (((document.documentElement.clientHeight - lay.offsetHeight) / 2 ) + document.documentElement.scrollTop);
			if(pos < 5){ pos = 5; }
			lay.style.top = pos + 'px';
			lay.style.visibility = 'visible';
			
			idRubro = rubro;
			addClasificados = new Object;
			remClasificados = new Object;
			
			posLayClas = document.documentElement.scrollTop;
			this.changePageClasificados(false, 1);
			stopLayMove = false;
		}
		this.loadLayClasificados = function(){
			if(wait){ return false; } 
			
			$('layPresupuestoCont').innerHTML = textLoading;
			
			wait = true;
			reqType = 'clasificados';
			
			var v = 'tipo' + SEP_IGUAL + reqType + SEP_AND;
			v += 'idRubro' + SEP_IGUAL + idRubro + SEP_AND;
			v += 'idsClasificados' + SEP_IGUAL + this.getClasificados() + SEP_AND;
			v += 'idIdioma' + SEP_IGUAL + ID_IDIOMA + SEP_AND;
			v += 'pagina' + SEP_IGUAL + paginaClasificados + SEP_AND;
			
			req.pedir(DIR_ROOT + 'requests/presupuesto.php', v);
		}
		this.closeLayClasificados = function(evt){
			if(evt){ StopEvent(evt); }
			
			var lay = $('layPresupuesto');
			lay.style.top = '-2000px';
			lay.style.visibility = 'hidden';
			
			$('layPresupuestoBlock').style.display = 'none';
			$('layPresupuestoCont').innerHTML = '';
		}
		this.addLayClasificado = function(ele, id, name){
			if(!idRubro){ return false; }
			
			if(ele.checked){ 
				//no estaba cargado previamente
				if(!remClasificados[id]){
					addClasificados[id] = name;
				}
				else{ delete remClasificados[id]; }
				ele.parentNode.parentNode.className = 'on';
			}
			else{
				//no estaba cargado previamente
				if(!!addClasificados[id]){
					delete addClasificados[id];
				}
				else{ remClasificados[id] = name; }
				ele.parentNode.parentNode.className = '';
			}
		}
		this.aceptLayClasificados = function(evt){
			if(!idRubro){ return false; }
			if(evt){ StopEvent(evt); }
			
			var cont = $('presupuestoClasificadoAgregado' + idRubro);
			for(var id in addClasificados){
				
				if(this.addClasificado(false, idRubro, id)){
					
					var ele = document.createElement('li');
					ele.id = 'presupuestoClasificadoAgregado' + idRubro + '-' + id;
					ele.innerHTML = '<span onmouseover="oToolTip.mostrar(event, \''+addClasificados[id]+'\');" onmouseout="oToolTip.ocultar();">'+addClasificados[id]+'</span>'+
					'<a href="javascript:;" onclick="oPresupuesto.removeClasificado(event, this.parentNode, '+idRubro+', '+id+')" title="Eliminar" class="eliminar"></a>'+
					'<a href="javascript:;" onclick="oPresupuesto.openLayVerMas(event, '+id+')" title="Ver" class="ver"></a>';
					cont.insertBefore(ele, cont.lastChild);
				}
			}
			for(id in remClasificados){ this.removeClasificado(false, $('presupuestoClasificadoAgregado'+idRubro+'-'+id), idRubro, id); }
			
			scrollToPos(posLayClas);
			this.closeLayClasificados();
		}
		this.changePageClasificados = function(evt, page){
			if(evt){ StopEvent(evt); }
			paginaClasificados = page;
			stopLayMove = true;
			this.loadLayClasificados();
		}
		
		
		// Layer Ver Mas Info de Clasificado
		var idClasificado, idPlus = 'Lay', posLayMasInfo;
		this.openLayVerMas = function(evt, clasificado){
			if(evt){ StopEvent(evt); }
			if(wait){ return false; }
			
			var lay = $('layClasificadoBlock');
			setOpacity(70, lay);
			lay.style.display = 'block';
			
			lay = $('layClasificado');
			var pos = (((document.documentElement.clientHeight - lay.offsetHeight) / 2 ) + document.documentElement.scrollTop);
			if(pos < 5){ pos = 5; }
			lay.style.top = pos + 'px';
			lay.style.visibility = 'visible';
			
			idClasificado = clasificado;
			
			posLayMasInfo = document.documentElement.scrollTop;
			this.loadLayVerMas();
		}
		this.loadLayVerMas = function(){
			if(wait){ return false; } 
			
			$('layClasificadoCont').innerHTML = textLoading;
			
			wait = true;
			reqType = 'verMas';
			
			var v = 'tipo' + SEP_IGUAL + reqType + SEP_AND;
			v += 'idClasificado' + SEP_IGUAL + idClasificado + SEP_AND;
			v += 'idPlus' + SEP_IGUAL + idPlus + SEP_AND;
			v += 'idIdioma' + SEP_IGUAL + ID_IDIOMA + SEP_AND;
			
			req.pedir(DIR_ROOT + 'requests/presupuesto.php', v);
		}
		this.closeLayVerMas = function(evt, stopScroll){
			if(evt){ StopEvent(evt); }
			
			var lay = $('layClasificado');
			lay.style.top = '-2000px';
			lay.style.visibility = 'hidden';
			
			$('layClasificadoBlock').style.display = 'none';
			$('layClasificadoCont').innerHTML = '';
			
			oClasificados.removeClasActSol(idClasificado, idPlus);
			if(!stopScroll){ scrollToPos(posLayMasInfo); }
		}
		
		
		// Validacion de Preguntas
		var preguntas, respuestas = (Cookie.get('respuestas') == '')? '' : Cookie.get('respuestas');
		this.setPreguntaRespuesta = function(id, ele){
			var input = $(id);
			
			if(ele.type == 'checkbox'){
				
				if(input.value == ''){ input.value = input.idsEles = ','; }
				
				if(ele.checked){
					input.value += ele.value + ',';
					input.idsEles += ele.id + ',';
				}
				else{
					input.value = input.value.replace(',' + ele.value + ',', ',');
					input.idsEles = input.idsEles.replace(',' + ele.id + ',', ',');
				}
				
				if(input.value == ','){ input.value = input.idsEles = ''; }
			}
			else if(ele.type == 'radio' && ele.checked){
				input.value = ele.value;
				input.idEle = ele.id;
			}
			if(!!input.onblur){ input.onblur(); }
		}
		this.blurPreguntaRespuesta = function(id){
			var input = $(id);
			if(!!input.onblur){ input.onblur(); }
		}
		var inicializarPreguntas = function(){
			//
			preguntas = new Array;
			var ids = $('preguntasPresupuesto');
			if(ids.value == ''){ return false; }
			
			ids = ids.value.split(',');
			for(var i = 0, t = ids.length; i < t; i++){
				
				var input = $('preguntaPresupuesto'+ids[i]);
				input.__id = ids[i];
				
				if(!input.onblur){
					
					if(input.getAttribute('requerido') == 'si'){
						input.onblur = function(){
							if(this.value == '' || 
							  (this.getAttribute('tipo') == 'numero' && !erNumero.test(this.value)) ||
							  (this.getAttribute('tipo') == 'fecha' && !erFecha.test(this.value)) ||
							  (this.getAttribute('tipo') == 'sino' && !erSiNo.test(this.value))
							){ this.parentNode.className = errorClass; }
							else{ this.parentNode.className = ''; }
						}
					}
					else if(input.getAttribute('tipo') == 'numero'){
						input.onblur = function(){
							if(this.value == '' || !erNumero.test(this.value)){ this.parentNode.className = errorClass; }
							else{ this.parentNode.className = ''; }
						}
					}
					else if(input.getAttribute('tipo') == 'fecha'){
						input.onblur = function(){
							if(this.value == '' || !erFecha.test(this.value)){ this.parentNode.className = errorClass; }
							else{ this.parentNode.className = ''; }
						}
					}
					else if(input.getAttribute('tipo') == 'sino'){
						input.onblur = function(){
							if(this.value == '' || !erSiNo.test(this.value)){ this.parentNode.className = errorClass; }
							else{ this.parentNode.className = ''; }
						}
					}
				}
				
				preguntas.push(input);
			}
		}
		var validarPreguntas = function(){
			var vale = true;
			respuestas = '';
			
			for(var i = 0, t = preguntas.length; i < t; i++){
				var input = preguntas[i];
				
				if(!!input.onblur){
					input.onblur();
					if(input.parentNode.className == errorClass){ vale = true; }
				}
				respuestas += input.name + SEP_IGUAL + trim(input.value) + SEP_AND;
			}
			respuestas += getComentarios();
			
			Cookie.set('respuestas', respuestas);
			return vale;
		}
		var limpiarPreguntas = function(){
			for(var i = 0, ti = preguntas.length; i < ti; i++){
				var input = preguntas[i];
				var tipo = input.getAttribute('tipo');
				
				if(tipo == 'select'){ input.options[0].selected = true; }
				else if(input.value != ''){
					if(tipo == 'radio' || tipo == 'sino'){
						$(input.idEle).checked = false;
						input.idEle = '';
					}
					else if(tipo == 'checkbox'){
						var ids = input.idsEles.substr(1, input.idsEles.length - 2).split(',');
						for(var x = 0, tx = ids.length; x < tx; x++){ $(ids[x]).checked = false; }
						input.idsEles = '';
					}
					input.value = '';
				}
			}
		}
		
		
		// Envio de Presupuesto
		var datosPersonales = (Cookie.get('datosPersonales') == '')? '' : Cookie.get('datosPersonales');
		var nombreP, apellidoP, emailP, direccionP, cpP, telefonoP, errorP, cargandoP, validado = false, conErrores,
		paisP, provinciaP, provinciaNP, ciudadP, ciudadNP, barrioP, barrioNP;
		
		this.confirmar = function(evt, stopScroll){
			var error = false, t = '';
			
			conErrores = false;
			
			if(evt){ StopEvent(evt); }
			if(wait || (paso != 3 && !validado)){ return false; }
			
			if(!validado){
				inicializarConsulta();
				
				nombreP.onblur();
				if(nombreP.parentNode.className == errorClass){ error = true; }
				
				apellidoP.onblur();
				if(apellidoP.parentNode.className == errorClass){ error = true; }
				
				emailP.onblur();
				if(emailP.parentNode.className == errorClass){ error = true; }
				
				provinciaP.onblur();
				if(provinciaP.parentNode.className == errorClass){ error = true; }
				
				ciudadP.onblur();
				if(ciudadP.parentNode.className == errorClass){ error = true; }
				
				barrioP.onblur();
				if(barrioP.parentNode.className == errorClass){ error = true; }
				
				telefonoP.onblur();
				if(telefonoP.parentNode.className == errorClass){ error = true; }
				
				//
				if(!validarPreguntas()){ error = true; }
				
				nombreP.disabled = emailP.disabled = paisP.disabled = provinciaP.disabled = 
				ciudadP.disabled = barrioP.disabled = direccionP.disabled = cpP.disabled = 
				telefonoP.disabled = (error)? false : true;
				
				if(error){
					errorP.innerHTML = 'Complete o corrija los campos resaltados';
					errorP.style.display = 'block';
					conErrores = true;
					return false;
				}
			}
			
			errorP.style.display = 'none';
			cargandoP.style.display = 'block';
			
			wait = true;
			reqType = 'confirmar';
			
			t += 'tipo' + SEP_IGUAL + reqType + SEP_AND;
			t += getDatosPersonales();
			t += 'idIdioma' + SEP_IGUAL + ID_IDIOMA + SEP_AND;
			t += 'idsRubros' + SEP_IGUAL + this.getRubros() + SEP_AND;
			t += 'idsClasificados' + SEP_IGUAL + this.getClasificados() + SEP_AND;
			t += respuestas;
			
			req.pedir(DIR_ROOT + 'requests/presupuesto.php', t);
			if(!stopScroll){ scrollToPos(240); }
		}
		this.consultar = function(evt){
			
			if(evt){ StopEvent(evt); }
			if(wait || !validado || conErrores){ return false; }
			
			wait = true;
			reqType = 'consultar';
			
			var t = 'tipo' + SEP_IGUAL + reqType + SEP_AND;
			t += datosPersonales;
			t += 'idIdioma' + SEP_IGUAL + ID_IDIOMA + SEP_AND;
			t += 'idsRubros' + SEP_IGUAL + this.getRubros() + SEP_AND;
			t += 'idsClasificados' + SEP_IGUAL + this.getClasificados() + SEP_AND;
			t += respuestas;
			
			$('presupuesto').innerHTML = textLoading;
			
			req.pedir(DIR_ROOT + 'requests/presupuesto.php', t);
			
		}
		var inicializarConsulta = function(){
			
			validado = false;
			
			nombreP = $('nombrePresupuesto');
			if(!nombreP.onblur){
				nombreP.onblur = function(){
					var v = trim(this.value);
					if(v == '' || v.length < 3){ this.parentNode.className = errorClass; }
					else{ this.parentNode.className = ''; }
				}.closure(nombreP);
			}
			
			apellidoP = $('apellidoPresupuesto');
			if(!apellidoP.onblur){
				apellidoP.onblur = function(){
					var v = trim(this.value);
					if(v == '' || v.length < 3){ this.parentNode.className = errorClass; }
					else{ this.parentNode.className = ''; }
				}.closure(apellidoP);
			}
			
			emailP = $('emailPresupuesto');
			if(!emailP.onblur){
				emailP.onblur = function(){
					var v = trim(this.value);
					if(v == '' || !erEmail.test(v)){ this.parentNode.className = errorClass; }
					else{ this.parentNode.className = ''; }
				}.closure(emailP);
			}
			
			paisP = $('paisPresupuesto');
			if(!paisP.onchange){
				paisP.onchange = function(){
					provinciaP.disabled = ciudadP.disabled =
					barrioP.disabled = true;
					
					provinciaNP.style.display = ciudadNP.style.display = 
					barrioNP.style.display = 'none';
					
					reqType = 'provincias';
					
					var v = 'tipo' + SEP_IGUAL + reqType + SEP_AND;
					v += 'idPais' + SEP_IGUAL + paisP.value + SEP_AND;
					
					req.pedir(DIR_ROOT + 'requests/zonas_geograficas.php', v);
				};
			}
			
			provinciaP = $('provinciaPresupuesto');
			if(!provinciaP.onchange){
				provinciaP.onchange = function(){
					
					var v = trim(provinciaP.value);
					
					ciudadP.disabled = barrioP.disabled = true;
					provinciaNP.style.display = (v == '0')? '' : 'none';
					ciudadNP.style.display = barrioNP.style.display = 'none';
					
					if(erNumero.test(v) && v != ''){
						
						reqType = 'ciudades';
						
						var v = 'tipo' + SEP_IGUAL + reqType + SEP_AND;
						v += 'idProvincia' + SEP_IGUAL + provinciaP.value + SEP_AND;
						
						req.pedir(DIR_ROOT + 'requests/zonas_geograficas.php', v);
					}
				};
			}
			if(!provinciaP.onblur){
				provinciaP.onblur = function(){
					var v = trim(this.value);
					if(v == '' || !erNumero.test(v)){ this.parentNode.className = errorClass; }
					else{ provinciaNP.onblur(); }
				}.closure(provinciaP);
			}
			
			provinciaNP = $('provinciaNombrePresupuesto');
			if(!provinciaNP.onblur){
				provinciaNP.onblur = function(){
					var v = trim(this.value);
					if(provinciaP.value == '0' && (v == '' || v.length < 3)){ this.parentNode.className = errorClass; }
					else{ this.parentNode.className = ''; }
				}.closure(provinciaNP);
			}
			
			ciudadP = $('ciudadPresupuesto');
			if(!ciudadP.onchange){
				ciudadP.onchange = function(){
					
					var v = trim(ciudadP.value);
					
					barrioP.disabled = true;
					ciudadNP.style.display = (v == '0')? '' : 'none';
					barrioNP.style.display = 'none';
					
					if(erNumero.test(v) && v != ''){
						
						reqType = 'barrios';
						
						var v = 'tipo' + SEP_IGUAL + reqType + SEP_AND;
						v += 'idCiudad' + SEP_IGUAL + ciudadP.value + SEP_AND;
						
						req.pedir(DIR_ROOT + 'requests/zonas_geograficas.php', v);
					}
				};
			}
			if(!ciudadP.onblur){
				ciudadP.onblur = function(){
					var v = trim(this.value);
					if(v == '' || !erNumero.test(v)){ this.parentNode.className = errorClass; }
					else{ ciudadNP.onblur(); }
				}.closure(ciudadP);
			}
			
			ciudadNP = $('ciudadNombrePresupuesto');
			if(!ciudadNP.onblur){
				ciudadNP.onblur = function(){
					var v = trim(this.value);
					if(ciudadP.value == '0' && (v == '' || v.length < 3)){ this.parentNode.className = errorClass; }
					else{ this.parentNode.className = ''; }
				}.closure(ciudadNP);
			}
			
			barrioP = $('barrioPresupuesto');
			if(!barrioP.onchange){
				barrioP.onchange = function(){
					
					var v = trim(barrioP.value);
					barrioNP.style.display = (v == '0')? '' : 'none';
				};
			}
			if(!barrioP.onblur){
				barrioP.onblur = function(){
					var v = trim(this.value);
					if(v == '' || !erNumero.test(v)){ this.parentNode.className = errorClass; }
					else{ barrioNP.onblur(); }
				}.closure(barrioP);
			}
			
			barrioNP = $('barrioNombrePresupuesto');
			if(!barrioNP.onblur){
				barrioNP.onblur = function(){
					var v = trim(this.value);
					if(barrioP.value == '0' && (v == '' || v.length < 3)){ this.parentNode.className = errorClass; }
					else{ this.parentNode.className = ''; }
				}.closure(barrioNP);
			}
			
			telefonoP = $('telefonoPresupuesto');
			if(!telefonoP.onblur){
				telefonoP.onblur = function(){
					var v = trim(this.value);
					if(v == '' || v.length < 7){ this.parentNode.className = errorClass; }
					else{ this.parentNode.className = ''; }
				}.closure(telefonoP);
			}
			
			direccionP = $('direccionPresupuesto');
			cpP = $('cpPresupuesto');
			errorP = $('errorPresupuesto');
			cargandoP = $('cargandoPresupuesto');
			
			//
			inicializarPreguntas();
		}
		var getDatosPersonales = function(){
			datosPersonales = '';
			datosPersonales += 'nombre' + SEP_IGUAL + trim(nombreP.value) + SEP_AND;
			datosPersonales += 'apellido' + SEP_IGUAL + trim(apellidoP.value) + SEP_AND;
			datosPersonales += 'email' + SEP_IGUAL + trim(emailP.value) + SEP_AND;
			datosPersonales += 'idPais' + SEP_IGUAL + trim(paisP.value) + SEP_AND;
			datosPersonales += 'idProvincia' + SEP_IGUAL + trim(provinciaP.value) + SEP_AND;
			datosPersonales += 'idCiudad' + SEP_IGUAL + trim(ciudadP.value) + SEP_AND;
			datosPersonales += 'idBarrio' + SEP_IGUAL + trim(barrioP.value) + SEP_AND;
			datosPersonales += 'nombreProvincia' + SEP_IGUAL + trim(provinciaNP.value) + SEP_AND;
			datosPersonales += 'nombreCiudad' + SEP_IGUAL + trim(ciudadNP.value) + SEP_AND;
			datosPersonales += 'nombreBarrio' + SEP_IGUAL + trim(barrioNP.value) + SEP_AND;
			datosPersonales += 'direccion' + SEP_IGUAL + trim(direccionP.value) + SEP_AND;
			datosPersonales += 'cp' + SEP_IGUAL + trim(cpP.value) + SEP_AND;
			datosPersonales += 'telefono' + SEP_IGUAL + trim(telefonoP.value) + SEP_AND;
			
			Cookie.set('datosPersonales', datosPersonales);
			return datosPersonales;
		}
		var getComentarios = function(){
			var ids = rubros.substr(1, rubros.length - 2).split(',');
			var v = '', e;
			
			for(var i = 0, t = ids.length; i < t; i++){
				e = $('comentarioPresupuesto' + ids[i]);
				if(!!e){ v += 'comentario' + ids[i] + SEP_IGUAL + trim(e.value) + SEP_AND; }
			}
			
			return v;
		}
		var limpiarComentarios = function(){
			var ids = rubros.substr(1, rubros.length - 2).split(',');
			var v = '', e;
			
			for(var i = 0, t = ids.length; i < t; i++){
				e = $('comentarioPresupuesto' + ids[i]);
				if(!!e){ e.value = ''; }
			}
			
			return v;
		}
		
		
		// Validacion de Solapa de Pasos
		var totalRubrosElegidos = 0, totalClasificadosElegidos = 0;
		var canLoadStep = function(step){
			if(step > 1 && totalRubrosElegidos < 1){ return false; }
			else if(step > 2 && totalClasificadosElegidos < 1){ return false; }
			else if(step > 3 && (!validado || conErrores)){ return false; }
			else{ return true; }
		}
		this.showErrorLoadStep = function(evt, step){
			if(!canLoadStep(step)){
				var msj = (step == 2)? 'Debe seleccionar al menos un rubro' : ((step == 3)? 'Debe seleccionar al menos una empresa' : 'Debe completar el formulario');
				
				if(paso == 3){
					if(conErrores){ msj = 'Debe completar los campos resaltados'; }
					else if(!validado){ return false; }
				}
				
				oTooltip.mostrar(evt, msj, 'ToolTipError');
			}
		}
		this.hideErrorLoadStep = function(){
			oTooltip.ocultar();
		}
		
		
		// 
		this.setTotalRubrosElegidos = function(num){
			totalRubrosElegidos = Number(num);
		}
		this.setTotalClasificadosElegidos = function(num){
			totalClasificadosElegidos = Number(num);
		}
		
		
		// Mi Prespuesto
		this.initMiPrespuesto = function(){
			var empresas = 0;
			var eleMsj = $('miPresupuestoCantidadEmpresas');
			var eleBtn = $('miPresupuestoCrear');
			
			if(!eleMsj || !eleBtn){ return false; }
			else if(rubros == ','){
				eleMsj.innerHTML = '';
				eleBtn.innerHTML = 'Crear';
			}
			else{
				if(rubros != ',' && clasificados != ','){
					var cantClasificados = clasificados.substr(1, clasificados.length - 2).split(',');
					for(var i in cantClasificados){
						var d = cantClasificados[i].split('-');
						if((RegExp(','+d[0]+',').test(rubros))){ empresas++; }
					}
				}
				
				eleMsj.innerHTML = empresas + ' ' + ((empresas == 1)? 'empresa agregada' : 'empresas agregadas');
				eleBtn.innerHTML = 'Modificar';
			}
			//
		}
	}
	
	
