//resolucion ticket 16081
function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}
//////////////////////////////////////////////////////////////////////////////////////
//Inicio resolucion ticket 71 ////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
 
//   Versiï¿½n JavaScript de la funcionalidad .NET - Server.HtmlDecode
//   Recibe un string con codificaciï¿½n HTML y convierte dicha codificaciï¿½n en literal
function HtmlDecode(s){
      var out = "";
      if (s==null) return;
      var l = s.length;
      for (var i=0; i<l; i++){
            var ch = s.charAt(i);
            if (ch == '&'){
                var semicolonIndex = s.indexOf(';', i+1);
				if (semicolonIndex > 0){
 					var entity = s.substring(i + 1, semicolonIndex);
					if (entity.length > 1 && entity.charAt(0) == '#'){
						if (entity.charAt(1) == 'x' || entity.charAt(1) == 'X')
							ch = String.fromCharCode(eval('0'+entity.substring(1)));
						else
							ch = String.fromCharCode(eval(entity.substring(1)));
					}
					else{
						switch (entity){
							case 'quot': ch = String.fromCharCode(0x0022); break;
                    		case 'amp': ch = String.fromCharCode(0x0026); break;
                    		case 'lt': ch = String.fromCharCode(0x003c); break;
		                    case 'gt': ch = String.fromCharCode(0x003e); break;
		                    case 'nbsp': ch = String.fromCharCode(0x00a0); break;
		                    case 'iexcl': ch = String.fromCharCode(0x00a1); break;
		                    case 'cent': ch = String.fromCharCode(0x00a2); break;
		                    case 'pound': ch = String.fromCharCode(0x00a3); break;
		                    case 'curren': ch = String.fromCharCode(0x00a4); break;
		                    case 'yen': ch = String.fromCharCode(0x00a5); break;
		                    case 'brvbar': ch = String.fromCharCode(0x00a6); break;
		                    case 'sect': ch = String.fromCharCode(0x00a7); break;
		                    case 'uml': ch = String.fromCharCode(0x00a8); break;
		                    case 'copy': ch = String.fromCharCode(0x00a9); break;
		                    case 'ordf': ch = String.fromCharCode(0x00aa); break;
		                    case 'laquo': ch = String.fromCharCode(0x00ab); break;
		                    case 'not': ch = String.fromCharCode(0x00ac); break;
		                    case 'shy': ch = String.fromCharCode(0x00ad); break;
		                    case 'reg': ch = String.fromCharCode(0x00ae); break;
		                    case 'macr': ch = String.fromCharCode(0x00af); break;
		                    case 'deg': ch = String.fromCharCode(0x00b0); break;
		                    case 'plusmn': ch = String.fromCharCode(0x00b1); break;
		                    case 'sup2': ch = String.fromCharCode(0x00b2); break;
		                    case 'sup3': ch = String.fromCharCode(0x00b3); break;
		                    case 'acute': ch = String.fromCharCode(0x00b4); break;
		                    case 'micro': ch = String.fromCharCode(0x00b5); break;
		                    case 'para': ch = String.fromCharCode(0x00b6); break;
		                    case 'middot': ch = String.fromCharCode(0x00b7); break;
		                    case 'cedil': ch = String.fromCharCode(0x00b8); break;
		                    case 'sup1': ch = String.fromCharCode(0x00b9); break;
		                    case 'ordm': ch = String.fromCharCode(0x00ba); break;
		                    case 'raquo': ch = String.fromCharCode(0x00bb); break;
		                    case 'frac14': ch = String.fromCharCode(0x00bc); break;
		                    case 'frac12': ch = String.fromCharCode(0x00bd); break;
		                    case 'frac34': ch = String.fromCharCode(0x00be); break;
		                    case 'iquest': ch = String.fromCharCode(0x00bf); break;
		                    case 'Agrave': ch = String.fromCharCode(0x00c0); break;
		                    case 'Aacute': ch = String.fromCharCode(0x00c1); break;
		                    case 'Acirc': ch = String.fromCharCode(0x00c2); break;
		                    case 'Atilde': ch = String.fromCharCode(0x00c3); break;
		                    case 'Auml': ch = String.fromCharCode(0x00c4); break;
		                    case 'Aring': ch = String.fromCharCode(0x00c5); break;
		                    case 'AElig': ch = String.fromCharCode(0x00c6); break;
		                    case 'Ccedil': ch = String.fromCharCode(0x00c7); break;
		                    case 'Egrave': ch = String.fromCharCode(0x00c8); break;
		                    case 'Eacute': ch = String.fromCharCode(0x00c9); break;
		                    case 'Ecirc': ch = String.fromCharCode(0x00ca); break;
		                    case 'Euml': ch = String.fromCharCode(0x00cb); break;
		                    case 'Igrave': ch = String.fromCharCode(0x00cc); break;
		                    case 'Iacute': ch = String.fromCharCode(0x00cd); break;
		                    case 'Icirc': ch = String.fromCharCode(0x00ce ); break;
		                    case 'Iuml': ch = String.fromCharCode(0x00cf); break;
		                    case 'ETH': ch = String.fromCharCode(0x00d0); break;
		                    case 'Ntilde': ch = String.fromCharCode(0x00d1); break;
		                    case 'Ograve': ch = String.fromCharCode(0x00d2); break;
		                    case 'Oacute': ch = String.fromCharCode(0x00d3); break;
		                    case 'Ocirc': ch = String.fromCharCode(0x00d4); break;
		                    case 'Otilde': ch = String.fromCharCode(0x00d5); break;
		                    case 'Ouml': ch = String.fromCharCode(0x00d6); break;
		                    case 'times': ch = String.fromCharCode(0x00d7); break;
		                    case 'Oslash': ch = String.fromCharCode(0x00d8); break;
		                    case 'Ugrave': ch = String.fromCharCode(0x00d9); break;
		                    case 'Uacute': ch = String.fromCharCode(0x00da); break;
		                    case 'Ucirc': ch = String.fromCharCode(0x00db); break;
		                    case 'Uuml': ch = String.fromCharCode(0x00dc); break;
		                    case 'Yacute': ch = String.fromCharCode(0x00dd); break;
		                    case 'THORN': ch = String.fromCharCode(0x00de); break;
		                    case 'szlig': ch = String.fromCharCode(0x00df); break;
		                    case 'agrave': ch = String.fromCharCode(0x00e0); break;
		                    case 'aacute': ch = String.fromCharCode(0x00e1); break;
		                    case 'acirc': ch = String.fromCharCode(0x00e2); break;
		                    case 'atilde': ch = String.fromCharCode(0x00e3); break;
		                    case 'auml': ch = String.fromCharCode(0x00e4); break;
		                    case 'aring': ch = String.fromCharCode(0x00e5); break;
		                    case 'aelig': ch = String.fromCharCode(0x00e6); break;
		                    case 'ccedil': ch = String.fromCharCode(0x00e7); break;
		                    case 'egrave': ch = String.fromCharCode(0x00e8); break;
		                    case 'eacute': ch = String.fromCharCode(0x00e9); break;
		                    case 'ecirc': ch = String.fromCharCode(0x00ea); break;
		                    case 'euml': ch = String.fromCharCode(0x00eb); break;
		                    case 'igrave': ch = String.fromCharCode(0x00ec); break;
		                    case 'iacute': ch = String.fromCharCode(0x00ed); break;
		                    case 'icirc': ch = String.fromCharCode(0x00ee); break;
		                    case 'iuml': ch = String.fromCharCode(0x00ef); break;
		                    case 'eth': ch = String.fromCharCode(0x00f0); break;
		                    case 'ntilde': ch = String.fromCharCode(0x00f1); break;
		                    case 'ograve': ch = String.fromCharCode(0x00f2); break;
		                    case 'oacute': ch = String.fromCharCode(0x00f3); break;
		                    case 'ocirc': ch = String.fromCharCode(0x00f4); break;
		                    case 'otilde': ch = String.fromCharCode(0x00f5); break;
		                    case 'ouml': ch = String.fromCharCode(0x00f6); break;
		                    case 'divide': ch = String.fromCharCode(0x00f7); break;
		                    case 'oslash': ch = String.fromCharCode(0x00f8); break;
		                    case 'ugrave': ch = String.fromCharCode(0x00f9); break;
		                    case 'uacute': ch = String.fromCharCode(0x00fa); break;
		                    case 'ucirc': ch = String.fromCharCode(0x00fb); break;
		                    case 'uuml': ch = String.fromCharCode(0x00fc); break;
		                    case 'yacute': ch = String.fromCharCode(0x00fd); break;
		                    case 'thorn': ch = String.fromCharCode(0x00fe); break;
		                    case 'yuml': ch = String.fromCharCode(0x00ff); break;
		                    case 'OElig': ch = String.fromCharCode(0x0152); break;
		                    case 'oelig': ch = String.fromCharCode(0x0153); break;
		                    case 'Scaron': ch = String.fromCharCode(0x0160); break;
		                    case 'scaron': ch = String.fromCharCode(0x0161); break;
		                    case 'Yuml': ch = String.fromCharCode(0x0178); break;
		                    case 'fnof': ch = String.fromCharCode(0x0192); break;
		                    case 'circ': ch = String.fromCharCode(0x02c6); break;
		                    case 'tilde': ch = String.fromCharCode(0x02dc); break;
		                    case 'Alpha': ch = String.fromCharCode(0x0391); break;
		                    case 'Beta': ch = String.fromCharCode(0x0392); break;
		                    case 'Gamma': ch = String.fromCharCode(0x0393); break;
		                    case 'Delta': ch = String.fromCharCode(0x0394); break;
		                    case 'Epsilon': ch = String.fromCharCode(0x0395); break;
		                    case 'Zeta': ch = String.fromCharCode(0x0396); break;
		                    case 'Eta': ch = String.fromCharCode(0x0397); break;
		                    case 'Theta': ch = String.fromCharCode(0x0398); break;
		                    case 'Iota': ch = String.fromCharCode(0x0399); break;
		                    case 'Kappa': ch = String.fromCharCode(0x039a); break;
		                    case 'Lambda': ch = String.fromCharCode(0x039b); break;
		                    case 'Mu': ch = String.fromCharCode(0x039c); break;
		                    case 'Nu': ch = String.fromCharCode(0x039d); break;
		                    case 'Xi': ch = String.fromCharCode(0x039e); break;
		                    case 'Omicron': ch = String.fromCharCode(0x039f); break;
		                    case 'Pi': ch = String.fromCharCode(0x03a0); break;
		                    case ' Rho ': ch = String.fromCharCode(0x03a1); break;
		                    case 'Sigma': ch = String.fromCharCode(0x03a3); break;
		                    case 'Tau': ch = String.fromCharCode(0x03a4); break;
		                    case 'Upsilon': ch = String.fromCharCode(0x03a5); break;
		                    case 'Phi': ch = String.fromCharCode(0x03a6); break;
		                    case 'Chi': ch = String.fromCharCode(0x03a7); break;
		                    case 'Psi': ch = String.fromCharCode(0x03a8); break;
		                    case 'Omega': ch = String.fromCharCode(0x03a9); break;
		                    case 'alpha': ch = String.fromCharCode(0x03b1); break;
		                    case 'beta': ch = String.fromCharCode(0x03b2); break;
		                    case 'gamma': ch = String.fromCharCode(0x03b3); break;
		                    case 'delta': ch = String.fromCharCode(0x03b4); break;
		                    case 'epsilon': ch = String.fromCharCode(0x03b5); break;
		                    case 'zeta': ch = String.fromCharCode(0x03b6); break;
		                    case 'eta': ch = String.fromCharCode(0x03b7); break;
		                    case 'theta': ch = String.fromCharCode(0x03b8); break;
		                    case 'iota': ch = String.fromCharCode(0x03b9); break;
		                    case 'kappa': ch = String.fromCharCode(0x03ba); break;
		                    case 'lambda': ch = String.fromCharCode(0x03bb); break;
		                    case 'mu': ch = String.fromCharCode(0x03bc); break;
		                    case 'nu': ch = String.fromCharCode(0x03bd); break;
		                    case 'xi': ch = String.fromCharCode(0x03be); break;
		                    case 'omicron': ch = String.fromCharCode(0x03bf); break;
		                    case 'pi': ch = String.fromCharCode(0x03c0); break;
		                    case 'rho': ch = String.fromCharCode(0x03c1); break;
		                    case 'sigmaf': ch = String.fromCharCode(0x03c2); break;
		                    case 'sigma': ch = String.fromCharCode(0x03c3); break;
		                    case 'tau': ch = String.fromCharCode(0x03c4); break;
		                    case 'upsilon': ch = String.fromCharCode(0x03c5); break;
		                    case 'phi': ch = String.fromCharCode(0x03c6); break;
		                    case 'chi': ch = String.fromCharCode(0x03c7); break;
		                    case 'psi': ch = String.fromCharCode(0x03c8); break;
		                    case 'omega': ch = String.fromCharCode(0x03c9); break;
		                    case 'thetasym': ch = String.fromCharCode(0x03d1); break;
		                    case 'upsih': ch = String.fromCharCode(0x03d2); break;
		                    case 'piv': ch = String.fromCharCode(0x03d6); break;
		                    case 'ensp': ch = String.fromCharCode(0x2002); break;
		                    case 'emsp': ch = String.fromCharCode(0x2003); break;
		                    case 'thinsp': ch = String.fromCharCode(0x2009); break;
		                    case 'zwnj': ch = String.fromCharCode(0x200c); break;
		                    case 'zwj': ch = String.fromCharCode(0x200d); break;
		                    case 'lrm': ch = String.fromCharCode(0x200e); break;
		                    case 'rlm': ch = String.fromCharCode(0x200f); break;
		                    case 'ndash': ch = String.fromCharCode(0x2013); break;
		                    case 'mdash': ch = String.fromCharCode(0x2014); break;
		                    case 'lsquo': ch = String.fromCharCode(0x2018); break;
		                   	case 'rsquo': ch = String.fromCharCode(0x2019); break;
		                  	case 'sbquo': ch = String.fromCharCode(0x201a); break;
		                   	case 'ldquo': ch = String.fromCharCode(0x201c); break;
		                   	case 'rdquo': ch = String.fromCharCode(0x201d); break;
		                   	case 'bdquo': ch = String.fromCharCode(0x201e); break;
		                   	case 'dagger': ch = String.fromCharCode(0x2020); break;
		                   	case 'Dagger': ch = String.fromCharCode(0x2021); break;
		                   	case 'bull': ch = String.fromCharCode(0x2022); break;
		                   	case 'hellip': ch = String.fromCharCode(0x2026); break;
		                   	case 'permil': ch = String.fromCharCode(0x2030); break;
		                   	case 'prime': ch = String.fromCharCode(0x2032); break;
		                   	case 'Prime': ch = String.fromCharCode(0x2033); break;
		                   	case 'lsaquo': ch = String.fromCharCode(0x2039); break;
		                   	case 'rsaquo': ch = String.fromCharCode(0x203a); break;
		                   	case 'oline': ch = String.fromCharCode(0x203e); break;
		                   	case 'frasl': ch = String.fromCharCode(0x2044); break;
		                   	case 'euro': ch = String.fromCharCode(0x20ac); break;
		                   	case 'image': ch = String.fromCharCode(0x2111); break;
		                   	case 'weierp': ch = String.fromCharCode(0x2118); break;
		                   	case 'real': ch = String.fromCharCode(0x211c); break;
		                   	case 'trade': ch = String.fromCharCode(0x2122); break;
		                   	case 'alefsym': ch = String.fromCharCode(0x2135); break;
		                   	case 'larr': ch = String.fromCharCode(0x2190); break;
		                   	case 'uarr': ch = String.fromCharCode(0x2191); break;
		                   	case 'rarr': ch = String.fromCharCode(0x2192); break;
		                   	case 'darr': ch = String.fromCharCode(0x2193); break;
		                   	case 'harr': ch = String.fromCharCode(0x2194); break;
		                   	case 'crarr': ch = String.fromCharCode(0x21b5); break;
		                   	case 'lArr': ch = String.fromCharCode(0x21d0); break;
		                   	case 'uArr': ch = String.fromCharCode(0x21d1); break;
		                   	case 'rArr': ch = String.fromCharCode(0x21d2); break;
		                   	case 'dArr': ch = String.fromCharCode(0x21d3); break;
		                   	case 'hArr': ch = String.fromCharCode(0x21d4); break;
		                   	case 'forall': ch = String.fromCharCode(0x2200); break;
		                   	case 'part': ch = String.fromCharCode(0x2202); break;
		                   	case 'exist': ch = String.fromCharCode(0x2203); break;
		                   	case 'empty': ch = String.fromCharCode(0x2205); break;
		                   	case 'nabla': ch = String.fromCharCode(0x2207); break;
		                   	case 'isin': ch = String.fromCharCode(0x2208); break;
		                   	case 'notin': ch = String.fromCharCode(0x2209); break;
		                   	case 'ni': ch = String.fromCharCode(0x220b); break;
		                    case 'prod': ch = String.fromCharCode(0x220f); break;
		                    case 'sum': ch = String.fromCharCode(0x2211); break;
		                    case 'minus': ch = String.fromCharCode(0x2212); break;
		                    case 'lowast': ch = String.fromCharCode(0x2217); break;
		                    case 'radic': ch = String.fromCharCode(0x221a); break;
		                    case 'prop': ch = String.fromCharCode(0x221d); break;
		                    case 'infin': ch = String.fromCharCode(0x221e); break;
		                    case 'ang': ch = String.fromCharCode(0x2220); break;
		                    case 'and': ch = String.fromCharCode(0x2227); break;
		                    case 'or': ch = String.fromCharCode(0x2228); break;
		                    case 'cap': ch = String.fromCharCode(0x2229); break;
		                    case 'cup': ch = String.fromCharCode(0x222a); break;
		                    case 'int': ch = String.fromCharCode(0x222b); break;
		                    case 'there4': ch = String.fromCharCode(0x2234); break;
		                    case 'sim': ch = String.fromCharCode(0x223c); break;
		                    case 'cong': ch = String.fromCharCode(0x2245); break;
		                    case 'asymp': ch = String.fromCharCode(0x2248); break;
		                    case 'ne': ch = String.fromCharCode(0x2260); break;
		                    case 'equiv': ch = String.fromCharCode(0x2261); break;
		                    case 'le': ch = String.fromCharCode(0x2264); break;
		                    case 'ge': ch = String.fromCharCode(0x2265); break;
		                    case 'sub': ch = String.fromCharCode(0x2282); break;
		                    case 'sup': ch = String.fromCharCode(0x2283); break;
		                    case 'nsub': ch = String.fromCharCode(0x2284); break;
		                    case 'sube': ch = String.fromCharCode(0x2286); break;
		                    case 'supe': ch = String.fromCharCode(0x2287); break;
		                    case 'oplus': ch = String.fromCharCode(0x2295); break;
		                    case 'otimes': ch = String.fromCharCode(0x2297); break;
		                    case 'perp': ch = String.fromCharCode(0x22a5); break;
		                    case 'sdot': ch = String.fromCharCode(0x22c5); break;
		                    case 'lceil': ch = String.fromCharCode(0x2308); break;
		                    case 'rceil': ch = String.fromCharCode(0x2309); break;
		                    case 'lfloor': ch = String.fromCharCode(0x230a); break;
		                    case 'rfloor': ch = String.fromCharCode(0x230b); break;
		                    case 'lang': ch = String.fromCharCode(0x2329); break;
		                    case 'rang': ch = String.fromCharCode(0x232a); break;
		                    case 'loz': ch = String.fromCharCode(0x25ca); break;
		                    case 'spades': ch = String.fromCharCode(0x2660); break;
		                    case 'clubs': ch = String.fromCharCode(0x2663); break;
		                    case 'hearts': ch = String.fromCharCode(0x2665); break;
		                    case 'diams': ch = String.fromCharCode(0x2666); break;
		                    default: ch = ''; break;
						}
					}
           			i = semicolonIndex;
				}
            }
            out += ch;
      }
      return out;
}
function replaceKeyword(a) {
	var actionURL = a.getElementsByTagName('INPUT')[0].value.toString();
	var splittedURL = actionURL.split("?");
	var action = splittedURL[0];
	
	$D.get('keyword').value = YAHOO.lang.trim(a.title); 
	//Seteo el action en funcion a lo elegido
	$D.get('searchForm').action = action;
	var locality = $D.get('locality');	
	if(locality)
		locality.focus;
		
	
	//Inserta el tooltip de explicacion de uso de localidades si no hay localidad cargada
	if (locality && locality.value == ''){
		loadTooltipLocalities();
	}

	$D.replaceClass('suggest','open','close');
	
	var htm = [];
	var div = document.createElement('DIV');
	div.id = 'dynSuggestParams';		
	var parameter;
	var parameters = splittedURL[1].toString().split("&param;");
	//Comienzo de uno para obviar el "seed"
	for (var i=1; i<parameters.length; i++) {
		parameter = parameters[i].split("=");
		if(parameter[1] != '' && parameter[1] != null && parameter[0] != 'keyword' && parameter[0] != 'locality'){
			htm.push('<input type="hidden" id="'+ parameter[0]+ '" name="'+ parameter[0]+'" value="'+ parameter[1]+'"/>');
		}
	}
	div.innerHTML = htm.join('');
	
	if ( $D.get('dynSuggestParams') )
		$D.get('searchParamsSet').replaceChild(div, $D.get('dynSuggestParams'));
	else
		$D.get('searchForm').getElementsByTagName('FIELDSET')[0].appendChild(div);
		
}

function cleanURLSearch(){
	
	var action = $D.get('searchForm').action.split("/");
	action = action[action.length-1].split(".")[0].toLowerCase();
	var keywordToRemove = $D.get('keyword');
	var localityToRemove = $D.get('locality');
	
	switch(action){
		case "termsuggest": 
			keywordToRemove.parentNode.removeChild(keywordToRemove);
		break;
		case "advertisesuggest": 
			keywordToRemove.parentNode.removeChild(keywordToRemove);
			localityToRemove.parentNode.removeChild(localityToRemove);
		break;
	}
}

function drag(a) {
    var dd, target, targetText, startPos;
	var Dom = YAHOO.util.Dom;
	
	YAHOO.util.Event.onDOMReady(function() {
		document.onselectstart = function() {return false;} // inhabilito seleccion en ie
		//asigno un drag proxy al elemento seleccionado
		dd = new YAHOO.util.DDProxy(Dom.get(a.id));
		startPos = Dom.getXY(Dom.get(a.id));
		//devuelve el item a su lugar tras arrastrarlo
		var motion = null;
		//solo podra soltarse en el cajon de busqueda
		target = new YAHOO.util.DDTarget("keyword");
		targetText = new YAHOO.util.DDTarget("labelKeyword");
		
		dd.onDragDrop = function(e, id) {
	        Dom.setXY(Dom.get(a.id), startPos);
	 		motion = new YAHOO.util.Motion( 
	        	Dom.get(a.id), { points: { to: startPos } }, 
	        	0, 
	            YAHOO.util.Easing.easeNone);
	            	
			motion.animate();
			replaceKeyword(a);
			document.onselectstart = function() {return true;} // habilito seleccion para ie
		}
	    dd.onInvalidDrop = function(e) {
	        Dom.setXY(this.getEl(), startPos);
	        motion = new YAHOO.util.Motion( 
	        	Dom.get(a.id), { points: { to: startPos } }, 
	            0, 
	            YAHOO.util.Easing.easeNone);

			motion.animate();
			document.onselectstart = function() {return true;} // habilito seleccion para ie
			Stage._instance.suggestKeyword.bind('suggest','blur','close');
		}
	});
	
};
//////////////////////////////////////////////////////////////////////////////////////
//Fin resolucion ticket 71////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////

var Search = function Search() {

	var _stage = Stage.getInstance();
	var _self = this;

	var _lastSuggest = false;
	var _activateButNotSuggestCalled = true;

	var _setSlider = function setSlider(divs){
		_self.getElmsSlider = divs;
		setTimeout(function(){
			for (var i=0; i<divs.length; i++) {
				if($D.get(divs[i])){ Slider.newInstance(divs[i]); }
			}
		}, 25);
	};
	
	var _currentSuggestCol = 0;
	var _suggestCols = ['contentRubro', 'contentNombre', 'contentPalabra'];
	var _switchColumns = function switchColumns(direction) {
		var lastColumn = _suggestCols[_currentSuggestCol];
		_currentSuggestCol = Math.min(Math.max(_currentSuggestCol+direction, 0), 2);
		var column = _suggestCols[_currentSuggestCol];
		
		Slider.markElm(lastColumn, 'last');
		$Y.Dom.addClass(column, 'columnSelected');

		if(Slider.getSelectedIndex(column) >= 0){
			Slider.markElm(column, 'new');
		}else{
			Slider.stepForward(column);	
		}
	};
	
	var _removeEmptyInput = function _removeEmptyInput() {
		var formElms = $D.get('searchForm').getElementsByTagName('INPUT');
		for(var i = 0; i < formElms.length; i++) {
			if((formElms[i].type == 'text' || formElms[i].type == 'hidden') && formElms[i].value == '') {
				formElms[i].parentNode.removeChild(formElms[i]);
				i--;
			}
		}
	};
	
	var _setEventsSuggest = function setEventsSuggest(suggestObj){
		
		var toggleSuggest = function(f){
			if(f !== false){
					_stage.dataManager.toggleSuggest();
					_toogleSuggest('disable');
			}

			if(_stage.dataManager.getSuggest()){
				$D.removeClass('turnOffSuggest','active');
				$D.addClass('turnOnSuggest','active');
				
				$E.removeListener('turnOnSuggest','click', toggleSuggest);
				$E.addListener('turnOffSuggest','click', toggleSuggest);


				if(f !== false){
					_activateButNotSuggestCalled = false;
				}
			}else{


				$D.removeClass('turnOnSuggest','active');
				$D.addClass('turnOffSuggest','active');
				
				$E.addListener('turnOnSuggest','click', toggleSuggest);
				$E.removeListener('turnOffSuggest','click', toggleSuggest);
			}
		};
		toggleSuggest(false);
	};
	
		
	var _selectedItem = function(list){
		var selIndex = Slider.getSelectedIndex(list);
		if(selIndex > -1){
			var selectedLi = $D.get(list).getElementsByTagName('LI')[selIndex];
			var relMarket = selectedLi.getAttribute('rel');
			var idMarket = "";
			var descMarket = "";
			if(relMarket){
				idMarket = relMarket.split(':')[0];
				descMarket = relMarket.split(':')[1];
			}
			selectedLi = null;
			return {id:idMarket, desc:descMarket};
		}else{
			$E.on('locality','focus', Stage.changeValueInput,{label: 'labelLocality'});
			return {id:0, desc:''};
		}
		
	};

	var _initSuggestKeyword = function _init() {
		
		var suggestKeyword = new Suggest('keyword', 'suggest');
		
		/* Up-Down */
		suggestKeyword.on('up', function(){
			var column = _suggestCols[_currentSuggestCol];
			var selIndex = Slider.getSelectedIndex(column);
			var k =  Slider.stepBackward(column);
			if(!k){ k = $D.get('keyword').getAttribute('_value'); }
			$D.get('keyword').value = k;
		});
		
		suggestKeyword.on('down', function(){
			var keywordEl = $D.get('keyword');
			var column = _suggestCols[_currentSuggestCol];
			var k =  Slider.stepForward(column);
			if(typeof k !== 'undefined'){
				if(!keywordEl.getAttribute('_value')){
					keywordEl.setAttribute('_value', keywordEl.value);
				}
				$D.get('keyword').value = k;
			}
			keywordEl = null;
		});
		
		/* Left-Right */
		suggestKeyword.on('left', function(){ _switchColumns(-1); });
		suggestKeyword.on('right', function(){ _switchColumns(1); });
		
		/* Suggest */
		suggestKeyword.on('suggest', function(){
			var k = $D.get("keyword").value;
			$D.replaceClass('suggest', _getSuggestActiveClass(), 'keyword');
			var seed = Stage.nextSeed();

			//Inicio Resolución Ticket 71
			$D.get('searchForm').action = "search.do";
			if($D.get('dynSuggestParams'))
				$D.get('dynSuggestParams').innerHTML = "";
			//Fin Resolución Ticket 71

			// resolucion ticket 16081
			var url = 'suggest.do?seed=' + seed + '&keyword=' + encodeURIComponent(escape(k)); 
			var fctn = function(){
				$D.replaceClass('suggestContent','off','on');
				$D.replaceClass('suggest','close','open');
				_setSlider(['contentRubro','contentNombre','contentPalabra']);
				_setEventsSuggest();
				//Inicio ResoluciÃ³n ticket 116
				var nodos = $D.get('suggestContent').innerHTML.toString();
				if(nodos.search(/suggestTableData/) == -1){
					var htm = [];
					var p = document.createElement('P');
					var a = document.createElement('A');
					var typedKeyword = $D.get('keyword').value;
					var locality = $D.get('locality').value;
					var seed = Stage.nextSeed();
					
					//Modificacion de mensaje en caso de no tener suggest--------
					var htm = [''];
					htm.push('<div class="shaddow searchSprite"><!-- --></div>');
					htm.push('<p class="switchSuggest" id="switchSuggest">');
					htm.push('<a id="turnOnSuggest" href="#" class="active">on</a> | <a id="turnOffSuggest" href="#">off</a></p>');
					htm.push('<p class="desc"><b>No tenemos sugerencias exactas</b></p>');
					htm.push('<div class="hrSuggest searchSprite"><!-- --></div>');
					htm.push('<p class="leyend">Modific&aacute; tu consulta o busc&aacute; directamente <a href="search.do?seed=' + seed + '&keyword=' + typedKeyword + '&locality='+ locality +'">');
					htm.push("<strong>" + typedKeyword + "</strong></p>");
					
					$D.get('suggestContent').innerHTML = htm.join('');
					_setEventsSuggest();
					//----------------------------------------------------------------
					/*
					htm.push('Busc&aacute;: <a href="search.do?seed=' + seed + '&keyword=' + typedKeyword + '&locality='+ locality +'">');
					htm.push('	<strong>' + typedKeyword + '</strong>');
					htm.push('</a> en P&aacute;ginas Amarillas');
					p.className = 'leyend';
					p.innerHTML = htm.join('');
					
					var contenedor = $D.getElementsByClassName('suggestContent')[0];
					contenedor.innerHTML = '';
					contenedor.appendChild(p);
					*/
				}
				//Fin ResoluciÃ³n ticket 116
				//correccion para error de tab del suggest en ie
				$D.get("tab").style.display='none';
				$D.get("tab").style.display='block';
				//----
			}
			var req = new Request();
			req.getContent(url, 'suggestContent', fctn);
			
		});
				
		suggestKeyword.setEnabled(function(){ return _stage.dataManager.getSuggest(); });

		/* Open-Close */
		suggestKeyword.on('close', function(){
			if(!$D.hasClass('suggest','help')) {
				$D.replaceClass('suggest','open','close');
			}
		});
		suggestKeyword.bind('locality', 'focus', 'close');
	
		/* Submit */

		var _keywordSubmit = function () {
			var column = _suggestCols[_currentSuggestCol];
			var selIndex = Slider.getSelectedIndex(column);
			$D.get('seed').value = Stage.nextSeed();
			if(selIndex < 0){
				_removeEmptyInput();
				$D.get('searchForm').submit();
			}else{
				var selectedLi = $D.get(column).getElementsByTagName('LI')[selIndex];
				var anchor = selectedLi.getElementsByTagName('A')[0];
				window.location.href = anchor.href;
				anchor = null;
			}
		};

		suggestKeyword.on('submit', _keywordSubmit);

		suggestKeyword.bind('searchForm', 'submit', 'submit', function(){
			$D.get('seed').value = Stage.nextSeed();
			//Inicio resolución ticket 71
			cleanURLSearch();
			//Fin resolución ticket 71
			
			//Inicio Resolución ticket 138
			var stage = Stage.getInstance();
			var dm = stage.dataManager;
			var locality = $D.get('locality').value;
			
			if(YAHOO.lang.trim(locality).length == 0) {
				dm.clearMarket();
				dm.setMarketDesc('');
			} else if(YAHOO.lang.trim(locality) != YAHOO.lang.trim(dm.getMarketDesc())) {
				dm.clearMarket();
				dm.setMarketDesc(YAHOO.lang.trim(locality));
			}
	 		//Fin Resolución ticket 138
		});
	
		$E.on('keyword', 'blur', function() {
			if(this.value != '') {
				_lastSuggest = suggestKeyword;
			}
			
		});
		
		Gonow.stage.suggestKeyword = suggestKeyword;
		
	};
	
	var _initSuggestLocality = function _init() {
	
		var suggestLocality = new Suggest('locality', 'suggest');
		
		/* Suggest */
		suggestLocality.on('suggest', function(){
			$D.replaceClass('suggest', _getSuggestActiveClass(), 'locality');
			var locality = $D.get("locality");
			var k = locality.value;
			var url = 'suggestLocation.do?keyword=' + escape(k);
			if (locality.orderBy) {
				url += "&orderBy=" + locality.orderBy;
			}
			
			var fctn = function(){
				_setEventsSuggest();
				$D.removeClass('suggest','close');
				$D.addClass('suggest','open');
				$D.replaceClass('suggestContent','off','on');
				if($D.get('contentRubro')){ Slider.newInstance('contentRubro'); }
				$E.on('suggestRubro', 'click', _localitySubmit);
	
				// Bind order events
				suggestLocality.bind('titleLocalidad', 'click', 'suggest', function() {
					_toggleOrder($D.get('locality'), 'city');
					return true;
				});
				suggestLocality.bind('titleProvincia', 'click', 'suggest', function() {
					_toggleOrder($D.get('locality'), 'state');
					return true;
				});
			}
			
			var req = new Request();
			req.getContent(url, 'suggestContent', fctn);
		});
		
		/* Up-Down */
		suggestLocality.on('down', function(){
			var column = 'contentRubro';
			var localityEl = $D.get('locality');
			var k =  Slider.stepForward(column);
			var selItem = _selectedItem(column);
			if(typeof k !== 'undefined'){
				if(!localityEl.getAttribute('_value')){
					localityEl.setAttribute('_value', localityEl.value);
				}
				$D.get('locality').value = selItem.desc;
				_setLocalityTooltipValue(selItem.desc);
			}
			locality = null;
		});

		suggestLocality.on('up', function(){
			var column = 'contentRubro';
			var k =  Slider.stepBackward(column);
			var selItem = _selectedItem(column);
			if(!k){ k = $D.get('locality').getAttribute('_value'); }
			$D.get('locality').value = selItem.desc;
				_setLocalityTooltipValue(selItem.desc);
		});

		suggestLocality.setEnabled(function(){ return _stage.dataManager.getSuggest(); });

		/* Open-Close */
		suggestLocality.on('close', function(){
			if(!$D.hasClass('suggest','help')) {
				$D.replaceClass('suggest','open','close');
			}
		});
		suggestLocality.bind('keyword', 'focus', 'close');

		var _localitySubmit = function() {
			var column = 'contentRubro';
			var selIndex = Slider.getSelectedIndex(column);
			if(selIndex >= 0){
				var selItem = _selectedItem(column);
				$D.get('locality').value = selItem.desc;
				_setLocalityTooltipValue(selItem.desc);
				
				var stage = Stage.getInstance();
				var dm = stage.dataManager;
				
				dm.setMarket(selItem.id);
				dm.setMarketDesc(selItem.desc);
				$D.replaceClass('suggest','open','close');
			}
		};

		$E.on('locality', 'blur', function() {
			if(this.value != '') {
				var stage = Stage.getInstance();
				var dm = stage.dataManager;
				
				// clear locality if necessary
				var localityValue = $D.get('locality').value;
				if(YAHOO.lang.trim(localityValue).length == 0) {
					// clear locality
					dm.clearMarket();
					dm.setMarketDesc('');
					_initLocalityTooltip();
				} else if(YAHOO.lang.trim(localityValue) != YAHOO.lang.trim(dm.getMarketDesc())) {
					// search by market description
					dm.clearMarket();
					dm.setMarketDesc(YAHOO.lang.trim(localityValue));
					_initLocalityTooltip();
				}
				
				_lastSuggest = suggestLocality;
			}
		});

		/* Submit */
		suggestLocality.on('submit', _localitySubmit);
		Gonow.stage.suggestLocality = suggestLocality;

		_initLocalityTooltip();

	};

	var _initLocalityTooltip = function() {
		var container = $D.getAncestorByClassName('searchForm','rightBox');
		var tip = document.createElement('DIV');
		tip.style.top = document.location.hostname.indexOf('pdindustriales') != -1 ? "35px" : "55px";
		var htm = [];
		htm.push('<div class="tooltipContainer">');
		htm.push('	<div class="tooltipMiddle" id="tooltipMiddle">');
		htm.push('		<div id="localityTooltipCtd"><!-- --></div>');
		htm.push('	</div>');
		htm.push('	<div class="tooltipleft" id="tooltipLeft"><!-- --></div>');
		htm.push('	<div class="tooltipRight" id="tooltipRight"><!-- --></div>');
		if(YAHOO.env.ua.ie == 6) {
			htm.push('	<div id="localityTooltipIE6Ctd"><!-- --></div>');
		}
		htm.push('</div>');
	
		//container.appendChild(tip);
		document.body.appendChild(tip);

		tip.innerHTML = htm.join('');
		tip.id = 'localityTooltip';
		$D.addClass(tip, 'off');

		var localityOver = function() {
			if($D.get('locality').value !== '') {
				$D.replaceClass('localityTooltip','off','on');
			}	
		};

		$E.on('locality', 'mouseover', localityOver);
		$E.on('localityTooltip', 'mouseover', localityOver); 

		$E.on(['locality', 'localityTooltip'], 'mouseout', function() {
			$D.replaceClass('localityTooltip','on','off');
		});

		container = null; tip = null;
	};

	var _setLocalityTooltipValue = function(vl) {
		$D.get('localityTooltipCtd').innerHTML = vl;
		if(YAHOO.env.ua.ie == 6) {
			$D.get('localityTooltipIE6Ctd').innerHTML = vl;
		}
	};

	var _callActiveSuggest = function() {
		if(_lastSuggest && _stage.dataManager.getSuggest()) {
			_lastSuggest.callSuggest();
		}
	};
	
	var _showDefaultContent = function() {

		var msg = 'No hay sugerencias, empiece a digitar su consulta';
		if(!_stage.dataManager.getSuggest()){
			msg = 'Las sugerencias de b&uacute;squeda est&aacute;n desactivadas.';
		}

		var htm = [''];
		htm.push('<div class="shaddow searchSprite"><!-- --></div>');
		htm.push('<p class="switchSuggest" id="switchSuggest">');
		htm.push('<a id="turnOnSuggest" href="#" class="active">on</a> | <a id="turnOffSuggest" href="#">off</a></p>');
		htm.push('<p class="desc">'+msg+'</p>');
		$D.get('suggestContent').innerHTML = htm.join('');
		_setEventsSuggest();


		$D.replaceClass('suggestHelp','on','off');
	};

	var _getSuggestActiveClass = function() {
		var classesRE = new RegExp('(keyword|locality|help)');
		var className = $D.get('suggest').className;
		var result = classesRE.exec(className);
		return result != null ? result[1] : '';
	};
	
	var _toogleSuggest = function(action) {
		
		if(action == 'disable') {
			_showDefaultContent();
			$D.removeClass('suggest', _getSuggestActiveClass());
		}

		if($D.hasClass('suggest', 'open')) {
			$D.replaceClass('suggest', 'open', 'close');
		} else if($D.hasClass('suggest', 'close')) {
			if(!(new RegExp('keyword|locality|help')).test($D.get('suggest').className)) {

				if(!_activateButNotSuggestCalled && _lastSuggest) {
					_callActiveSuggest();
					_activateButNotSuggestCalled = true;
				} else {
					$D.replaceClass('suggest', 'close', 'open');
					_showDefaultContent();
				}
			} else {
				$D.replaceClass('suggest', 'close', 'open');
			}
		}
		
		//Inicio ResoluciÃ³n ticket 116
		var nodos = $D.get('suggestContent').innerHTML.toString();
		var typedKeyword = new String($D.get('keyword').value);
		if(nodos.search(/suggestTableData/) == -1 && typedKeyword.length > 0){
			var htm = [];
			var p = document.createElement('P');
			var locality = $D.get('locality').value;
			var seed = Stage.nextSeed();
			
			//Agregado para mensaje cuando no tengo habilitado suggest
			if(!_stage.dataManager.getSuggest()){
				htm.push('<div class="shaddow searchSprite"><!-- --></div>');
				htm.push('<p class="switchSuggest" id="switchSuggest">');
				htm.push('<a id="turnOnSuggest" href="#" class="active">on</a> | <a id="turnOffSuggest" href="#">off</a></p>');
				htm.push('<p class="desc">Las sugerencias de b&uacute;squeda est&aacute;n desactivadas.</p>');
			}else{
				htm.push('Busc&aacute;: <a href="search.do?seed=' + seed + '&keyword=' + typedKeyword + '&locality='+ locality +'">');
				htm.push('	<strong>' + typedKeyword + '</strong>');
				htm.push('</a> en P&aacute;ginas Amarillas');
				p.className = 'leyend';
			}
			//htm.push('Busc&aacute;: <a href="search.do?seed=' + seed + '&keyword=' + typedKeyword + '&locality='+ locality +'">');
			//htm.push('	<strong>' + typedKeyword + '</strong>');
			//htm.push('</a> en P&aacute;ginas Amarillas');
			
			p.innerHTML = htm.join('');
			
			var contenedor = $D.getElementsByClassName('suggestContent')[0];
			contenedor.innerHTML = '';
			contenedor.appendChild(p);
			//Agregado para mensaje cuando no tengo habilitado suggest
			if(!_stage.dataManager.getSuggest()){
				_setEventsSuggest();
			}
			//-------------------------------------------------------------
		}else{
			_showDefaultContent();
		}
		//Fin ResoluciÃ³n ticket 116
		
	};
		
	var _toggleOrder = function(el, orderFieldName) {
		if(el.orderBy && el.orderBy.indexOf(orderFieldName) != -1) {
			if(el.orderBy == (orderFieldName + '_asc')) {
				el.orderBy = orderFieldName + '_desc';
			} else {
				el.orderBy = orderFieldName + '_asc';
			}
		} else if(!el.orderBy) {
			el.orderBy = orderFieldName + '_desc';
		} else {
			el.orderBy = orderFieldName + '_asc';
		}
	}

	var _showHelpContent = function showHelpContent() {
		var request = new Request();
		request.getContent('help.jsp', 'helpContent');
		$D.replaceClass('suggest', _getSuggestActiveClass(), 'help');
		$D.replaceClass('suggestContent','on','off');
		$D.replaceClass('suggestHelp','off','on');
		setTimeout(function() { $D.replaceClass('suggest', 'close', 'open') }, 300);
		return false;
	};

	var _verifyEmptySearch = function() {
		var keyword = YAHOO.lang.trim($D.get('keyword').value);
		if(keyword == '') {
			alert('Informe el texto de la bï¿½squeda.');
			return false;
		}
		return true;
	};


	var _controlLabels = function() {
		$E.on('keyword','focus', Stage.changeValueInput,{label: 'labelKeyword'});

		if ($D.get('keyword').value === '') {
			$D.replaceClass('labelKeyword','off','onInline');
		} else {
			$D.replaceClass('labelKeyword','onInline','off');
		}
	
		if ($D.get('locality').value === '') {
			$D.replaceClass('labelLocality','off','onInline');
			$E.on('locality','focus', Stage.changeValueInput,{label: 'labelLocality'});
		} else {
			$D.replaceClass('labelLocality','onInline','off');
			// para habilitar a ediï¿½ï¿½o da localidade e consequentemente sua remoï¿½ï¿½o
			//$E.on('locality','focus', Stage.changeValueInput,{clearValue: true});
		}
	};

	var _beforeSubmitSearch = function() {
		var stage = Stage.getInstance();
		var dm = stage.dataManager;
		
		// validate search
		var valid = _verifyEmptySearch();
		if(!valid) {
			return false;
		}

		// clear locality if necessary
		var localityValue = $D.get('locality').value;
		if(YAHOO.lang.trim(localityValue).length == 0) {
			// clear locality
			dm.clearMarket();
			dm.setMarketDesc('');
		} else if(YAHOO.lang.trim(localityValue) != YAHOO.lang.trim(dm.getMarketDesc())) {
			// search by market description
			dm.clearMarket();
			dm.setMarketDesc(YAHOO.lang.trim(localityValue));
		}
		return true;
	}

	var _init = function(){
		var stage = Stage.getInstance();
		var dm = stage.dataManager;

		if(dm.getMarketDesc()){
			$D.get('locality').value = dm.getMarketDesc(); 
			_setLocalityTooltipValue(dm.getMarketDesc()); 
		}

		$E.on('locality', 'keyup', function(){
			if(dm.getMarketDesc()){
				_setLocalityTooltipValue($D.get('locality').value); 
			}		
		});

		_controlLabels();

		$E.on('btHelp','click', _showHelpContent);
		$E.on('btOpenSuggest', 'click', _toogleSuggest);
		$D.get('searchForm').onsubmit = _beforeSubmitSearch;
		$D.get("keyword").disabled = false;
		$D.get("locality").disabled = false;		
	};

	_initSuggestKeyword.call();
	_initSuggestLocality.call();
	_init.call();
};


function initLocalityTooltip() {
		var container = $D.getAncestorByClassName('searchForm','rightBox');
		var tip = document.createElement('DIV');
		tip.style.top = document.location.hostname.indexOf('pdindustriales') != -1 ? "34px" : "55px";
		var htm = [];
		htm.push('<div class="tooltipContainer">');
		htm.push('	<div class="tooltipMiddle" id="tooltipMiddle">');
		htm.push('		<div id="localityTooltipCtd"><!-- --></div>');
		htm.push('	</div>');
		htm.push('	<div class="tooltipleft" id="tooltipLeft"><!-- --></div>');
		htm.push('	<div class="tooltipRight" id="tooltipRight"><!-- --></div>');
		if(YAHOO.env.ua.ie == 6) {
			htm.push('	<div id="localityTooltipIE6Ctd"><!-- --></div>');
		}
		htm.push('</div>');
	
		//container.appendChild(tip);
		document.body.appendChild(tip);

		tip.innerHTML = htm.join('');
		tip.id = 'localityTooltip';
		$D.addClass(tip, 'off');

		var localityOver = function() {
			if($D.get('locality').value !== '') {
				$D.replaceClass('localityTooltip','off','on');
			}	
		};

		$E.on('locality', 'mouseover', localityOver);
		$E.on('localityTooltip', 'mouseover', localityOver); 

		$E.on(['locality', 'localityTooltip'], 'mouseout', function() {
			$D.replaceClass('localityTooltip','on','off');
		});

		container = null; tip = null;
	};

	
	//Retorna los estilos y posicion al tooltip standard
	function restoreTooltip(){
		if($D.get("locality") && $D.get('localityTooltipCtd'))
			$D.get('localityTooltipCtd').innerHTML = $D.get("locality").value;
		
		if(YAHOO.env.ua.ie == 6) {
			$D.get('localityTooltipIE6Ctd').innerHTML = $D.get("locality").value;
		}
	
		$D.replaceClass('tooltipMiddle','tooltipMiddle2', 'tooltipMiddle');
		$D.replaceClass('tooltipRight', 'tooltipRight2','tooltipRight');
		$D.replaceClass('tooltipLeft', 'tooltipLeft2','tooltipleft');
		
		var pos = "0";
		if(document.location.hostname.indexOf('pdindustriales') != -1)
			pos = findPosY($D.get("locality"))-29;
		else
			pos = findPosY($D.get("locality"))-30;
		
		//$D.get("localityTooltip").style.top = '80px';
		if(!$D.get("localityTooltip"))
			initLocalityTooltip();
		$D.get("localityTooltip").style.top = pos+"px";
		$D.get("localityTooltipCtd").style.left='0px'	
		
		if(YAHOO.env.ua.ie == 6) {
			$D.get("localityTooltipIE6Ctd").style.paddingTop='0px'
		} 	
	}
	
	//Modificacion de texto y tamaño del alt para localidades 
	function loadTooltipLocalities(){
		initLocalityTooltip();
		valor ="<p align='justify' style='line-height : 12px'>Puede especificar una provincia o <br/> localidad para hacer m&aacute;s precisa <br/>su b&uacute;squeda</p>";
		$D.get('localityTooltipCtd').innerHTML = valor;
		if(YAHOO.env.ua.ie == 6) {
			$D.get('localityTooltipIE6Ctd').innerHTML = valor;
		}
		
		$D.replaceClass('localityTooltip','off','on');
		$D.replaceClass('tooltipMiddle', 'tooltipMiddle', 'tooltipMiddle2');
		$D.replaceClass('tooltipRight', 'tooltipRight', 'tooltipRight2');
		$D.replaceClass('tooltipLeft', 'tooltipleft', 'tooltipLeft2');
		
		//-----
		var	pos = findPosY($D.get("locality"))-80;
		var posx = findPosX($D.get("locality"));
		$D.get("localityTooltip").style.top = pos +"px";
		$D.get("localityTooltip").style.left = posx +"px";
		//-----
		//$D.get("localityTooltip").style.top = '36px';
		$D.get("localityTooltipCtd").style.left='12px'
		if(YAHOO.env.ua.ie == 6) {
			$D.get("localityTooltipIE6Ctd").style.paddingTop='15px'
			$D.get("localityTooltipCtd").style.left='12px' 
		}
	}

  //Obtiene la posicion y de un elemento
  function findPosY(obj){
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }
	
  function findPosX(obj){
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }