
//LS3_JS_GLOBAL
var urlDflt ='http://www.mercadolidesa.com.ar/argentina/ml/';
var scriptName = '/argentina/ml/';


//LS3_JS_BASE_URL
var listBaseUrl = "http://listado.dereto.com.mx";

//LS3_JS_CORE
var dfltDivHTML = null;
var isLS3 = true;
var alwaysBanner = true;

var wordFocus = false;
netscape = "";
ver = navigator.appVersion; 
len = ver.length;
for(iln = 0; iln < len; iln++) {
	if (ver.charAt(iln) == "(") break;
}
netscape = (ver.charAt(iln+1).toUpperCase() != "C");

function setFocus(){
	wordFocus = true;
}

function setBlur(){
	wordFocus = false;
}

netscape = (ver.charAt(iln+1).toUpperCase() != "C");
function keyDown(DnEvents) {
	k = (netscape) ? DnEvents.which : window.event.keyCode;
	if (k == 13 && wordFocus==true) {
		innerSearch();
		return false;
	}else{
		return true;
	}
}
document.onkeydown = keyDown;
if (netscape) document.captureEvents(Event.KEYDOWN|Event.KEYUP);

function getChr(value) {
	var vHexCode = "0123456789ABCDEF"
	var hex = "" + vHexCode.charAt((value - (value % 16))/16) + vHexCode.charAt(value % 16)
	return unescape("%"+hex)
}

function encodeNatural(toEncode) {
	toEncode= toEncode.replace(/\+/g, getChr(254));
	toEncode= toEncode.replace(/-/g, getChr(216));
	toEncode= toEncode.replace(/\s/g, '-');
	toEncode= toEncode.replace(/\t/g, '-');
	toEncode= toEncode.replace(/_/g, '*');
	return encodeURIComponent(toEncode);
}
function innerSearch(){
	var urlToRedirect;
	var currentUrl = document.URL;
	var word = document.getElementById('as_inner_word').value;

	setCookie("ml_list","searching");	
	setCookie('LAST_SEARCH', word, null);	
	
	var otherParams = currentUrl.substring(currentUrl.lastIndexOf("/")+1);
	if (otherParams && otherParams.indexOf("_")>-1) {
		otherParams = otherParams.substring(otherParams.indexOf("_"));
	} else {
		otherParams = "";
	}

	var check=document.getElementById('categ_check');
	if (check != null && check.checked){
		var currentUrlPath = currentUrl.substring(0,currentUrl.lastIndexOf('/')+1);
		urlToRedirect = currentUrlPath + encodeNatural (word);
	}else{
		otherParams = otherParams.replace(/_CategID_[^_$]*/gi,"");
		otherParams = otherParams.replace(/_MetaCategIDs_[^_$]*/gi,"");
		urlToRedirect = listBaseUrl + "/" + encodeNatural(word);
	}

	if(getCookieValue('pr_categ') == 'AD' && otherParams.indexOf("_PrCategId_AD")==-1) {
		otherParams = otherParams + "_PrCategId_AD";
	}
	
	otherParams = otherParams.replace(/_Desde_[^_$]*/gi,"");
	otherParams = otherParams.replace(/_Qshow_[^_$]*/gi,"");
	otherParams = otherParams.replace(/_OrderId_[^_$]*/gi,"");
	otherParams = otherParams.replace(/_All_[^_$]*/gi,"");
	otherParams = otherParams.replace(/_EshopFilter_[^_$]*/gi,"");
	otherParams = otherParams.replace(/_FilterId_[^_$]*/gi,"");
	otherParams = otherParams.replace(/_FiltroId_[^_$]*/gi,"");
	otherParams = otherParams.replace(/_FiltroId2_[^_$]*/gi,"");
	otherParams = otherParams.replace(/_FiltroId3_[^_$]*/gi,"");
	otherParams = otherParams.replace(/_Bnr_[^_$]*/gi,"");
	otherParams = otherParams.replace(/_SearchBoth_[^_$]*/gi,"");
	otherParams = otherParams.replace(/_NickName_[^_$]*/gi,"");
	otherParams = otherParams.replace(/_CustId_[^_$]*/gi,"");

	otherParams = otherParams.replace(/_Marca_[^_$]*/gi,"");
	otherParams = otherParams.replace(/_Modelo_[^_$]*/gi,"");
	otherParams = otherParams.replace(/_YearMin_[^_$]*/gi,"");
	otherParams = otherParams.replace(/_YearMax_[^_$]*/gi,"");
	otherParams = otherParams.replace(/_noQCat_[^_$]*/gi,"");
	
	otherParams = otherParams.replace(/_PciaId_[^_$]*/gi,"");
	otherParams = otherParams.replace(/_OtherFilterID_[^_$]*/gi,"");
	otherParams = otherParams.replace(/_ItemTypeID_[^_$]*/gi,"");
	otherParams = otherParams.replace(/_AuctTypeID_[^_$]*/gi,"");
	otherParams = otherParams.replace(/_PriceMax_[^_$]*/gi,"");
	otherParams = otherParams.replace(/_PriceMin_[^_$]*/gi,"");

	otherParams = otherParams.replace(/_ProductID_[^_$]*/gi,"");
	otherParams = otherParams.replace(/_CantPuertas_[^_$]*/gi,"");
	otherParams = otherParams.replace(/_Combustible_[^_$]*/gi,"");
	otherParams = otherParams.replace(/_KmsMax_[^_$]*/gi,"");
	otherParams = otherParams.replace(/_KmsMin_[^_$]*/gi,"");
	
	otherParams = otherParams.replace(/_Qc_[^_$]*/gi,"");
	otherParams = otherParams.replace(/_Barrios_[^_$]*/gi,"");
	otherParams = otherParams.replace(/_Ambientes_[^_$]*/gi,"");
	otherParams = otherParams.replace(/_SupMin_[^_$]*/gi,"");
	otherParams = otherParams.replace(/_SupMax_[^_$]*/gi,"");
	otherParams = otherParams.replace(/_Ciudad_[^_$]*/gi,"");
	otherParams = otherParams.replace(/_MalertaOn_[^_$]*/gi,"");
	otherParams = otherParams.replace(/_AlertId_[^_$]*/gi,"");
	otherParams = otherParams.replace(/_OtherFilterID_[^_$]*/gi,"");
	otherParams = otherParams.replace(/_Aso_[^_$]*/gi,"");
	urlToRedirect = urlToRedirect + otherParams;
	document.location.href = urlToRedirect;

}
function getSubdomain(){		
	var dom = ""+window.location.host;
	var pos = dom.indexOf("mercadoli");
	if(pos == -1)
		pos = dom.indexOf("deremate");
	if(pos == -1)
		pos = dom.indexOf("arremate");
	if (pos != -1)	
		dom = dom.substring(pos);		
	return dom;
}

function getCookieValue(name) {
	var start=document.cookie.indexOf(name+"=");
	var len=start+name.length+1;
	if (start == -1) 
		return null;
	var end=document.cookie.indexOf(";",len);
	if (end==-1) 
		end=document.cookie.length;
	return unescape(document.cookie.substring(len,end));
}
function setCookie(cookieName,cookieValue,nDays) {
	setCookie(cookieName,cookieValue,nDays, null);
}		
function deleteCookie(name){
	setCookie(name,tmp,(new Date(1)));
}

function setCookie(cookieName,cookieValue,nDays,path) {
	var subdomain = getSubdomain();
	if (path == null)
		path ="/";
	if(nDays!=null){
		today  = new Date();
		expire = new Date();
		if (nDays==null || nDays==0) 
			nDays=1;
		expire.setTime(today.getTime() + 3600000*24*nDays);								
		document.cookie = cookieName+"="+cookieValue+";path="+path + ";domain=."+ subdomain +  ";expires="+expire.toGMTString();
	}
	else
		document.cookie = cookieName+"="+cookieValue+";path="+path+";domain=."+ subdomain;		
}

function setContextCookie(val){
	var urlBase=document.getElementsByTagName("base")[0].href.replace("www","pmspxl");
	urlBase=urlBase.substring(0,7+urlBase.substring(7).indexOf("/"));
	url = urlBase+"/jm/PmsPixel?ck="+val;
	var pixelDiv = document.getElementById("pmspxl");
	if(pixelDiv!=null)
		pixelDiv.innerHTML="<img width=0 height=0 src='"+url+"'>";
}

function performNaturalCheck(referrer, currentUrl){
	ind= getNaturalReferrerInd(referrer, currentUrl);
	if(ind == -1){
		return ;
	}
	pageId= getPageIdentification(currentUrl);
	
	naturalPmsSiteId= naturalPmsSiteIds[ind];
	naturalPmsId= naturalPmsIds[ind];
	
	key= "PMS"+naturalPmsId;
	setCookie("orgpms", naturalPmsSiteId, 30);
	setCookie("pmsword", pageId, 30);
	setCookie(key, key, 30);
}
function getPageIdentification(currentUrl){
	try{
		if ( oldUrl!=null){
			currentUrl= oldUrl;
		}
	}catch(e){}
	
	if(currentUrl.indexOf("jm/item") != -1)
		return "ITEM";
	if(currentUrl.indexOf("jm/search") != -1)
		return "SEARCH";
	if(currentUrl.indexOf("jm/themepage") != -1)
		return "THEMES";
	if(currentUrl.indexOf("/home")!= -1)
		return "HOME";
	if(currentUrl.indexOf("jm/guide")!= -1)
		return "GUIDES";
	if(currentUrl.indexOf("jm/catalog")!= -1)
		return "CATALOG";
	if(currentUrl.indexOf("jm/reviews")!= -1)
		return "REVIEWS";				
	if(currentUrl.length == 1 && currentUrl.lastIndexOf('/')==0)
		return "HOME";
	return "OTHER";	
}
function getNaturalReferrerInd(referrer, currentUrl){
	fromPms= getCookieValue("pmsonline");
	if(fromPms!=null){
		if(fromPms=="YES"){
			setCookie("pmsonline", currentUrl, null);
			return -1;
		}
		if(fromPms.toLowerCase()==currentUrl.toLowerCase())
			return -1;
	}
		
	iQueryIndex= referrer.indexOf("?");
	if(iQueryIndex != -1)
		referrer= referrer.substring(0, iQueryIndex);
	referrer= referrer.toLowerCase();
	finded= -1;
	for(var i= naturalSites.length-1; i>-1 && finded==-1; i--){
		if(referrer.indexOf(naturalSites[i])!=-1)
			finded = i;		
	}
	return finded;
}
function installListeners(){
	document.onclick= clickEvent;
	document.onkeypress= keyPressEvent;
}
function keyPressEvent(E){
	performPopPms();
}
function clickEvent(E){
	performPopPms();
}
function performPopPms(){
	var t_orgpms= getCookieValue("t_orgpms");
	if(t_orgpms){
		var t_cust_id = getCookieValue("t_cust_id");
		var t_pmsword= getCookieValue("t_pmsword");
		var key= "PMS"+t_cust_id;
		//Persistir cookies de PMS
		setCookie("orgpms", t_orgpms, 30);
		setCookie(key, key, 1);
		setCookie("pmsword", t_pmsword, 30);
		// Eliminar cookies temporales
		setCookie("t_orgpms", t_orgpms, -10);
		setCookie("t_pmsword", t_pmsword, -10);
		setCookie("t_cust_id", t_cust_id, -10);
	}
}
var tasksClick = new Array();
function addClickListener(task){
	if (task!=null)
		tasksClick[tasksClick.length]=task;	
	return;
}
document.onclick = clickFired;
function clickFired(E){
	for(var i =0 ; i <tasksClick.length; i++){
		tasksClick[i](E);
	}
	return;
}
var tasksKey=new Array();
function addKeyListener(task){
	if (task!=null)
		tasksKey[tasksKey.length]=task;	
	return;
}
document.onkeypress = keypressFired;
function keypressFired(E){
	for(var i =0 ; i <tasksKey.length; i++){
		tasksKey[i](E);
	}
	return;
}

function getUrlPath(str){
            pos = str.indexOf("//");
            pos = str.indexOf("/",pos+2);
            relative = str.substring(pos);
            pos= relative.indexOf("?");
            return relative.substring(0, pos);
}

function getUrlQueryString(str){
            pos = str.indexOf("//");
            pos = str.indexOf("/",pos+2);
            relative = str.substring(pos);
            pos= relative.indexOf("?");
            return relative.substring(pos);
}
function getTrackCookie(){
  if(getCookieValue("clicked")== null || getCookieValue("clicked")=="0"){	
  	var value = getCookieValue("track_info");
  	if(value!=null){
  		arrayKeys = value.split(":");   	
  		var out = "/jm/ml.track.me?save_ck=N";
  		for (i=1; i < arrayKeys.length; i++)
    		out += "&k"+i+"="+arrayKeys[i];
		var img = new Image().src = out;
	  	setCookie("clicked","1",null);
  	}
  }
}
function getBase(urlBase){
	pos = urlBase.indexOf("//")+2;
	if (pos != -1){
		urlBasePart = urlBase.substring(pos);
	}else{
		alert("Error: URL Invalida");
	}
	
	pos2 = urlBasePart.indexOf("/")+pos;
	
	if (pos2 == -1)
		alert("Error: URL Invalida");
		
	return urlBase.substring(0,pos2);	
}

function setPrCategLink(lnk)
{
    var c=getCookieValue("pr_categ");
    if (c==null) 
    	c="";

    if (lnk.substring(0,1)=="/"){
    	base = getBase(document.getElementsByTagName('base')[0].href);
    }else{
    	base = document.getElementsByTagName('base')[0].href;
    }    	    
    window.location=base+lnk+"&as_pr_categ_id="+c;
}
function setLogPMS(){
	v = window.location.pathname;
	if ( v.indexOf("jms") > 0 || v.indexOf("org_item_abm") > 0 || v.indexOf("org_item_categ") > 0 || v.indexOf("l_calif.calif_users") > 0 || v.indexOf("l_calif.my_calif") > 0 || v.indexOf("l_calif.replay_users") > 0 || v.indexOf("l_calif.my_history") > 0 || v.indexOf("org_bid.ofertar") > 0 || v.indexOf("org_bid_new.ofertar") > 0 || v.indexOf("org_pago_placetopay") > 0 || v.indexOf("org_pagoitu") > 0)
	return;
	ck = getCookieValue("orguserid");

	urlPath= self.location.pathname;
	urlPath = urlPath.substr(1,urlPath.length);
	urlQueryString= self.location.search;
	try{
		if(oldUrl!=null){
			urlPath= getUrlPath(oldUrl);
			urlQueryString= getUrlQueryString(oldUrl);
		}
	}
	catch(Exception){
	}


	if (ck==null||ck.length < 4 ){
		document.write("<a target=\"_top\" href=\"/jm/login?url="+escape(urlPath)+escape(urlQueryString)+"\" class=hpcateg id=\"MENU:ENTRAR\">Entrar</a>");
		} else {
			document.write("<a target=\"_top\" href=\"/jm/logout\" class=hpcateg id=\"MENU:SALIR\">Salir</a>");

		}
}
function setTrackCookie(e){ 
	if (window.event) 
		e = window.event; 
	var srcEl = e.srcElement? e.srcElement : e.target;
        if(srcEl.id==null||srcEl.id=='') 
		srcEl = (srcEl.parentElement?srcEl.parentElement:srcEl.parentNode);
        var track = srcEl.id;
	if (track != null && track.indexOf(":")!=-1){
	   arr = track.split("$");
  	   trackID = arr[0];
  	   if(document.home_track_id && document.home_track_id!='')
  	       trackID=document.home_track_id+':'+trackID;
   	   setCookie("track_info",document.track_site_id+":"+trackID,null);
    	   setCookie("clicked","0",null);
        }
}

setCookie("cookieEnabled","true",null);
if(Math.random() < .5 && document.cookie.indexOf("cookieEnabled=true")!=-1) {
	out1 = "";
	var i = 1;
	if(document.home_track_id){
		arr_home_track_id = document.home_track_id.split(":");
		for(i=1;i<=arr_home_track_id.length;i++)
		out1 += "&k"+i+"="+arr_home_track_id[i-1];
	}
	var obj = ( document.layers? document.layers : (!document.getElementsByTagName && document.all ? document.all : document.getElementsByTagName("*")) );
	for(j=0;j<obj.length;j++){
		if(obj[j].id != null && obj[j].id.indexOf("$p")>0){
			out2 = out1;
			arr = obj[j].id.split("$");
			arrayKeys = arr[0].split(":");
			for (k=0; k < arrayKeys.length; k++)
			out2 += "&k"+(k+i)+"="+arrayKeys[k];
			document.write('<img src="/jm/ml.track.me?p=Y'+out2+'" width=1 height=1 border=0 bordercolor=white>') ;
		}
	}

}
var w;
var wLoaded = false;
var NOT_FOUND = -1;
//var queryString = window.location.search;
var queryString = oldUrl.substr(oldUrl.indexOf("?"));
var oldPath = oldUrl.substr(0,oldUrl.indexOf("?"));
function getTopPos(pHeight){return (screen.height)?(screen.height-pHeight)/2:0;}
function getLeftPos(pWidth){return (screen.width)?(screen.width-pWidth)/2:0;}
function getURL(){
    //return location.pathname+queryString;
    return oldPath+queryString;
}
function getTrackURL(){
    return (location.pathname+queryString).replace(/&/gi, "\$\$\$\$");
}

function imgLog(k1, k2, k3, k4, k5, k6, k7){	
	rnd = Math.random(); 
	if ( rnd < .5 ){
		var out = "<img width=1 height=1 border=0 bordercolor=white src=\"/jm/ml.track.me?p=Y";
		if ( k1 != null )	out += "&k1="+k1;
		if ( k2 != null )	out += "&k2="+k2;
		if ( k3 != null )	out += "&k3="+k3;
		if ( k4 != null )	out += "&k4="+k4;
		if ( k5 != null )	out += "&k5="+k5;
		if ( k6 != null )	out += "&k6="+k6;
		if ( k7 != null )	out += "&k7="+k7;
		out += "&r="+(Math.round(rnd*100000))+"\">";
		document.write(out);
	} else {
		var out = "<img src=\"/org-img/t.gif\" width=1 height=1 border=0 bordercolor=white>";
	}
}
function h(lnk, k1, k2, k3, k4, k5, k6, k7){
 var c=getCookieValue("pr_categ");
 if (c==null) c=""; 
 out = ""; 
 if ( k1 != null ) {
 	out += "&k1="+k1;
 } else {
 	window.location=lnk+"&as_pr_categ_id="+c;
 	return;
 } 	
 if ( k2 != null )	out += "&k2="+k2;
 if ( k3 != null )	out += "&k3="+k3;
 if ( k4 != null )	out += "&k4="+k4;
 if ( k5 != null )	out += "&k5="+k5;
 if ( k6 != null )	out += "&k6="+k6;
 if ( k7 != null )	out += "&k7="+k7; 
 window.location.href="/jm/ml.track.me?"+out+"&go="+lnk+"&as_pr_categ_id="+c; 
}

function wOpen(pURL, pName, w, h, scroll, text, specialSettings){
	xLeft=(screen.width)?(screen.width-w)/2:0;
	xTop=(screen.height)?(screen.height-h)/2:0;
	xSettings = 'height='+h+',width='+w+',top='+xTop+',left='+xLeft+',scrollbars='+scroll+specialSettings
	hwnd = window.open(pURL,pName,xSettings);
	if(hwnd.window.focus){hwnd.window.focus();}
	if(text != "") {
		hwnd.document.write(text);
		hwnd.document.close();
	}
	return hwnd;
}

function desplHiddenValues(id){
  var obj = document.getElementById(id).style;
    if(obj.display=='none'||obj .display==''){
     obj .display = 'block';
    }else{ 
     obj .display = 'none';
    }
}


var shownWindow;
var contentLoaded = true;

function openWindow(windowID){
	//
	if (!contentLoaded) return ;
	if (shownWindow != null) hideWindow();
	
	var loadingDiv = document.getElementById( windowID );
	//var screenSize = getScreenSize();	
	var screenSize={screenW:0,screenH:0};
	if(window.innerWidth){
		screenSize.screenW = window.innerWidth;
		screenSize.screenH = window.innerHeight;
	}else if (document.documentElement && document.documentElement.clientWidth){
		screenSize.screenW = document.documentElement.clientWidth;
		screenSize.screenH = document.documentElement.clientHeight;
	}else if (document.body){
		screenSize.screenW = document.body.clientWidth;
		screenSize.screenH = document.body.clientHeight;
	}
	
	var cwidth = "470";
	var cheight= "255";
	
	var cleft = (screenSize.screenW/2) - (cwidth / 2)  ;
//	var cleft = 0  ;
//	var ctop = (screenSize.screenH -cheight) / 3 ;
//	var ctop = 0;
var ctop = V( document.getElementById( "cont_ord_view" ) ,"offsetTop");
	//var loadingDiv = document.createElement('div');
	
	if( loadingDiv.style.setAttribute ){ //IE
		//loadingDiv.style.setAttribute('position',	'absolute');
		loadingDiv.style.setAttribute('left', parseInt(cleft ));
		loadingDiv.style.setAttribute('top', parseInt(ctop));		
		loadingDiv.style.setAttribute('visibility','visible');
		
		//alert(loadingDiv.style.getAttribute('visibility');
	}else{
		loadingDiv.setAttribute('style',"position:absolute;left:"+cleft+"px;top:"+ctop+"px;visibility:visible");
	}
	
	//div.setAttribute('id','shownWindow');
	
	shownWindow = loadingDiv;
	//document.body.appendChild(shownWindow);
	
}

function hideWindow(){	
	//alert("hider");
	if (shownWindow == null) return ;	
	if( shownWindow.style.setAttribute ){//IE
		shownWindow.style.setAttribute( "visibility" , "hidden" );
	}else{
		shownWindow.setAttribute("style","visibility:hidden;position:absolute");		
	}
	shownWindow = null;
}

function setContentLoaded(){
	document.onclick = executeClick;
	contentLoaded = true;
}

function getScreenSize(){
	var screenW = 0, screenH = 0;
	if (parseInt(navigator.appVersion)>3) {
	 screenW = screen.width;
	 screenH = screen.height;
	}
	else if (navigator.appName == "Netscape" 
	    && parseInt(navigator.appVersion)==3
    	&& navigator.javaEnabled()
	   ) 
	{
	 var jToolkit = java.awt.Toolkit.getDefaultToolkit();
	 var jScreenSize = jToolkit.getScreenSize();
	 screenW = jScreenSize.width;
	 screenH = jScreenSize.height;
	}
	retval={screenW:0,screenH:0};
	retval.screenW = screenW;
	retval.screenH = screenH;	
	return retval;
}


function executeClick(e){
alert("click");
	if (window.event) e = window.event;
	var srcEl = e.srcElement? e.srcElement : e.target;
	hideWindowByClick(srcEl);
	
}

function hideWindowByClick(srcElement){
	var parent=srcElement;
	while( parent != null ){
		if (parent.id == 'shownWindow') return ;
		parent = parent.offsetParent;
	}
	hideWindow();
}


function realignOpenCombo(  ){
}

function getSearchCookie(){
	if(getCookieValue("search_flag")=="1"){
		var img = new Image().src = "/jm/ml.track.me?save_ck=N&k1=MENU&k2=SEARCH";
		setCookie("search_flag","0",null);
	}
}

// flags del banner
var lowResolution=false;
var downloadBanner=false;

function hideBanner(){
	var banner = document.getElementById("oasTOP");	
	banner.style.display="none";
}
function expandBanner(){
	var banner = document.getElementById("oasTOP");	
	if(banner.style.setAttribute){
		banner.style.setAttribute("height",'90px');
		banner.style.setAttribute("visibility","visible");
	}else{
		banner.setAttribute("style","visibility:visible;height:90px");
	}
}

function getWindowSize() {
  var width = 0, height = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    width = window.innerWidth;
    height = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    width = document.documentElement.clientWidth;
    height = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    width = document.body.clientWidth;
    height = document.body.clientHeight;
  }
  var size = new Array(width, height);
  return size;
}

function createTag(filename, filetype){
 if (filetype=="js"){
  var fileref=document.createElement('script');
  fileref.setAttribute("type","text/javascript");
  fileref.setAttribute("src", filename);
 }
 else if (filetype=="css"){
  var fileref=document.createElement("link");
  fileref.setAttribute("rel", "stylesheet");
  fileref.setAttribute("type", "text/css");
  fileref.setAttribute("href", filename);
 }
 if (typeof fileref!="undefined")
  document.getElementsByTagName("head")[0].appendChild(fileref);
}

function loadBannerScript(pageId, categId){
	if(alwaysBanner || !hasScrolled()){
		createTag('/jm/ml.advbanners.advBanners?page_id='+pageId+'&categ_id='+categId+'','js');
		createTag('http://www.mercadolibre.com/org-img/advertising/oas.js','js');
	}
}


function setSizeFlags() {
	var size = getWindowSize();
	lowResolution = size[0]<=800 || size[1]<=500;
}

window.onscroll = function() {
	realignOpenCombo();
}
window.onresize  = function() {
	realignOpenCombo();
	setSizeFlags();
}

function hasScrolled(){
	var offset = 0;
	if (document.documentElement && document.documentElement.scrollTop){
		offset=document.documentElement.scrollTop;
	}else{

		if (document.all) { //MSIE
			offset = window.document.documentElement.scrollTop;
		}
		else { 
			offset=window.pageYOffset;
		}
	}
	
	if(offset>90){
		return true;	
	}else{
		return false;
	}
}

if(alwaysBanner){
//window.onload = expandBanner;
}

//document.onscroll = realignOpenGlobito;
document.onclick = hideHelp;
		
		var helpPop;
		var baseT;
		var baseL;
		var popY;
		var popX;
		var hideFlag = false;
		
		function asd(){
		                alert(helpPop.style.getAttribute('top'));
		                alert(helpPop.style.getAttribute('left'));
		}
		
		function showHelp(pop_id,clickevent,pos) {
		
			hideHelp();
		
			if (document.all) { // MSIE
				var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body;
				popX = clickevent.clientX;
				popY = clickevent.clientY;
				baseT = iebody.scrollTop;
				baseL = iebody.scrollLeft;
                                popX += baseL;
                                popY +=baseT;
			} else { // Netscape, etc.
				popX = clickevent.clientX;
				popY = clickevent.clientY;
				baseT = window.pageYOffset
				baseL = window.pageXOffset
                                popX += baseL;
                                popY +=baseT;
			}
		
			popY += 31;
			popX -= 140;
	 
			helpPop = document.getElementById(pop_id);

			var flecha;
			for (i=0; i<helpPop.childNodes.length; i++){
				if (helpPop.childNodes[i].className=="caja_ayu_flecha"){
					flecha = helpPop.childNodes[i];
				}
			}
			if( helpPop.style.setAttribute ){ //IE

				if(pos=='R'){
					popX -= 115; 
					flecha.style.setAttribute('left', '242px');
				}else{
					flecha.style.setAttribute('left', '130px');
				}

				helpPop.style.setAttribute('display', 'block');
				helpPop.style.setAttribute('visibility','visible');
				helpPop.style.setAttribute('top',parseInt(popY)+'px');
			helpPop.style.setAttribute('left',parseInt(popX)+'px');
		        helpPop.style.setAttribute('z-index','3');
			}else{
				if(pos=='R'){
					popX -= 115; 
					flecha.style.left = '242px';
				}else{
					flecha.style.left = '130px';
				}
				helpPop.setAttribute('style',"display:block;visibility:visible;top:"+parseInt(popY)+"px;left:"+parseInt(popX)+"px;position:absolute");

			}
			hideFlag=false;
		}
		
		var intervalID;
		function delayHide( millis ){
			if (millis == null) millis = 1000;
			deleteDelayHide();
			intervalID = setInterval('hideHelp();', millis);
		}
		
		function deleteDelayHide(){
			window.clearInterval( intervalID );
		}
		
		function hideHelp(){
			if(hideFlag){
				if(helpPop!=null){
					if( helpPop.style.setAttribute ){ //IE
						helpPop.style.setAttribute('display', 'none');
						helpPop.style.setAttribute('visibility','hidden');
					}else{
						helpPop.setAttribute('style',"display:none;visibility:hidden;");
					}
					helpPop = null;
				}
			}else{
				hideFlag=true;
			}
		}
		
		function realignOpenGlobito(){
			if(helpPop!=null){
				var offsetT;
				var offsetL;
				if (document.all) { // MSIE
					offsetT = document.body.scrollTop;
					offsetL = document.body.scrollLeft;
				} else { // Netscape, etc.
					offsetT = window.pageYOffset
					offsetL = window.pageXOffset
				}
				var diffT = baseT-offsetT;
				var diffL = baseL-offsetL;
				
				if( helpPop.style.setAttribute ){ //IE
					helpPop.style.setAttribute('top',parseInt(diffT+popY));
					helpPop.style.setAttribute('left',parseInt(diffL+popX));
				}else{
					helpPop.setAttribute('style',"top:"+parseInt(diffT+popY)+"px;left:"+parseInt(diffL+popX)+"px;position:fixed");
				}
			}
		}
		
		
	function logoutTargetUrl() {
	  var baseUrl = document.getElementsByTagName('base')[0].href;
	  baseUrl = baseUrl.substring(0,baseUrl.indexOf("/",7));
	  var redirectUrl = oldUrl.substring(oldUrl.indexOf("/",7)+1);
	  window.location=baseUrl+"/jm/logout?urlTo="+escape(redirectUrl);
	}
		
	function setLog(){
	  ck = getCookieValue("orguserid"); 
	  if (ck!=null && ck.length >= 4 ) {       
	       document.write("<div class=\"lnk_menu_der\"><a target=\"_top\" href=\"javascript:logoutTargetUrl();\" class=\"hpcateg\" id=\"MENU:SALIR\">"+lblLogout+"</a></div>");
  }  
	}

function mli(){
	if (w && document.all) 
		w.close();
	w=window.open(urlDflt+"p_html?as_html_id=POP_UPMERCADOLIDER","par","top="+getTopPos(400)+",left="+getLeftPos(430)+",width=430,height=400,toolbar=no,resizable=no,scrollbars=yes");
}

function mligold(){
	if (w && document.all)
		w.close();
	w=window.open(urlDflt+"p_html?as_html_id=POP_UPMERCADOLIDERG","par","top="+getTopPos(400)+",left="+getLeftPos(430)+",width=430,height=400,toolbar=no,resizable=no,scrollbars=yes");
}

function mliplat(){
	if (w && document.all) 
		w.close();
	w=window.open(urlDflt+"p_html?as_html_id=POP_UPMERCADOLIDERP","par","top="+getTopPos(400)+",left="+getLeftPos(430)+",width=430,height=400,toolbar=no,resizable=no,scrollbars=yes");
}
function certif()

{
    wOpen("http://www.mercadolibre.cl/chile/ml/p_html?as_html_id=CERTIF", "", 450, 430, "no", "", "outerWidth=460,outerHeight=440");
}

var Url = {
 	encode : function (string) {
 		 return escape(this._utf8_encode(string));
 	},
	
	 decode : function (string) {
 	 	return this._utf8_decode(unescape(string));
 	},

 	_utf8_encode : function (string) {
  		string = string.replace(/\r\n/g,"\n");
 	 	var utftext = "";

  		for (var n = 0; n < string.length; n++) {
   			var c = string.charCodeAt(n);
   			if (c < 128) {
    				utftext += String.fromCharCode(c);
 			} else if((c > 127) && (c < 2048)) {
  				utftext += String.fromCharCode((c >> 6) | 192);
  				utftext += String.fromCharCode((c & 63) | 128);
 			} else {
  				utftext += String.fromCharCode((c >> 12) | 224);
  				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
 	 			utftext += String.fromCharCode((c & 63) | 128);
 			}
 	}

		return utftext;
	},

 	_utf8_decode : function (utftext) {
 		 var string = "";
 		 var i = 0;
 		 var c = c1 = c2 = 0;

  		while ( i < utftext.length ) {
  			 c = utftext.charCodeAt(i);
   			if (c < 128) {
    				string += String.fromCharCode(c);
    				i++;
  			 } else if((c > 191) && (c < 224)) {
 				   c2 = utftext.charCodeAt(i+1);
    				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
    				i += 2;
  			 } else {
 				   c2 = utftext.charCodeAt(i+1);
    				c3 = utftext.charCodeAt(i+2);
    				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
   				 i += 3;
 			  }
		  }
		return string;
	 }
}

function replaceWeirdChars( word ) {
	word = word.replace('Á','A');
	word = word.replace('É','E');
	word = word.replace('Í','I');
	word = word.replace('Ó','O');
	word = word.replace('Ú','U');
	word = word.replace(/\./g,"");
	return word;
}

function appendQcatFilters() {
	url = document.location.href ; 
	partes = url.split('/'); 
	url = partes[partes.length-1];
	partes = url.split('_'); 
	url = 'Query='+replaceWeirdChars(Url.decode(partes[0]))+'&' ;
	i=1;
	while (i<partes.length) {
		url += partes[i] +'='+ replaceWeirdChars(Url.decode(partes[i+1]))+ '&' ;
		i+=2;
	}
	url = url.substring(0,url.length-1);
	return url;
}

//LS3_JS_PULSE
//pls_track.js

function loadTrackImage(siteId, categId, word){
	var searchedWord= getCookieValue('LAST_SEARCH');
	if(categId==null||categId==''){
		categId= 'NULL';
	}
	if(word!=null&&searchedWord!=null&&word==searchedWord){
		var request= '<img width=1 height=1 border=0 bordercolor=white src=\"http://pulsecnt.mercadolibre.com/jm/ml.web.pulse.WordCounterServlet?as_site_id='+siteId+'&as_categ_id='+categId+'&as_word='+word+'\">';
		document.write(request);
	}
}


//LS3_JS_PMS
//pmspixel.js
function setSearchCookie(word){
	var searching = getCookieValue("ml_list");		
	if(searching !="searching")
		return;	
	if(word!=null && word != "")
		setContextCookie("S"+word);
	setCookie("ml_list","");
		
}
function pmsCtxCk(word,categ){
	if(word!=""){		
		var links = document.getElementsByTagName("a");
		for(i=0;i<links.length;i++){
			if(links[i].toString().indexOf("http://articulo.")!=-1 || links[i].toString().indexOf("http://produto.")!=-1 || links[i].toString().indexOf("/jm/item?")!=-1){			
				setSearchCookie(word);
				break;
			}
		}	
	}else{	
		if(categ!="" && categ!="##CATEG_L2##"){
			setContextCookie('V'+categ);
		}
	}	
}

//LS3_JS_LOGOUT
var lblLogout = "Salir";

