/*-------- IMPORT FROM ( Name [ syi4/SellerRegView.js ], Type [ WebComponetFile  ] ) --------*/
var sellerRegOn = false;
var gDivID = 'divReg';

function showRegSeller()
{
	var regDiv = document.getElementById(gDivID);
	
	auxDivHeight = getDimension(regDiv.style.height);
	auxDivWidth = getDimension(regDiv.style.width);
	
	auxTop = getDivTop(gDivID);
	auxLeft = getDivLeft(gDivID);
	
	try {
		//solo para avanzados, invisible el arbol para IE6
		if(userLevel == 'ADV') {
			hideTreeCateg();
		}
	}catch(e) {}//no es un usuario avanzado
	
	displayFloatingDiv(gDivID, auxLeft, auxTop, auxDivHeight, auxDivWidth);
}

function displayFloatingDiv(divID, pLeft, pTop, pHeight, pWidth) 
{
	sellerRegOn = true;
	//con esto acomodo los 2 divs si el usuario modifica el tamaño del navegador
	window.onresize = resizeDivs;
	createDimmerDiv();
	
	regDiv = document.getElementById(gDivID);
	regDiv.style.left = pLeft;
	regDiv.style.top = pTop;
	regDiv.style.display = 'block';
}

function hiddenFloatingDiv() {
	sellerRegOn = false;
	document.getElementById(gDivID).style.display='none';
	document.getElementById('dimmer').style.display = 'none';
}

function createDimmerDiv() {
	divDimmer = document.getElementById('dimmer');
	if(divDimmer == null){
		element = document.createElement("div");
		element.style.height = getDimmerDivHeight();
		element.style.width = getDimmerDivWidth();
		element.id="dimmer";
		document.getElementsByTagName('body')[0].appendChild(element);
	}else{
		divDimmer.style.display = 'block';
	}
}

function getDimmerDivWidth() {
	awidth = window.screen.width;//document.body.scrollWidth;
	return awidth;
}

function getDimmerDivHeight() {
	aheight = window.screen.height; //document.body.scrollHeight
	return aheight;
}

function getDivTop(divID){
	vDiv = document.getElementById(divID);
	bodyHeight = document.body.clientHeight;
	auxDivHeight = 232;//getDimension(vDiv.offsetHeight);
	auxTop = (bodyHeight - auxDivHeight)/2;
	if(auxTop < 15) auxTop = 15;
	return auxTop;
}

function getDivLeft(divID){
	vDiv = document.getElementById(divID);
	bodyWidth = document.body.clientWidth;
	auxDivWidth = getDimension(vDiv.style.width);
	auxLeft = (bodyWidth - auxDivWidth)/2;
	return auxLeft;
}

function resizeDivs(){
	if(sellerRegOn){
		//dimmer
		divDimmer = document.getElementById('dimmer');
		divDimmer.style.height = getDimmerDivHeight();
		divDimmer.style.width = getDimmerDivWidth();
		//fin dimmer
		
		//div
		divReg = document.getElementById(gDivID);
		lTop = getDivTop(gDivID);
		lLeft = getDivLeft(gDivID);
		divReg.style.top = lTop;
		divReg.style.left = lLeft;
		//fin div
	}
}

function getDimension(dim){
	return parseInt(dim.replace("px", ""));
}

function comenzar()
{
	var ok = true;
	for(key in regErrors){
		if($(key+'ErrTxt')){
        		if($(key+'ErrImg')){
          			$(key+'ErrImg').style.display = 'none';
        		}
        		$(key+'ErrTxt').style.display = 'none';
        	}
	}
	if(document.getElementsByName('as_doc_number')) {
		if(document.getElementsByName('as_doc_number').length > 0 && document.getElementsByName('as_doc_number')[0].value == ''){
			setRegError('as_doc_number');
			vInner1 = false;
			ok = false;
		}
	}
	if(document.getElementsByName('as_address1')) {
		if(document.getElementsByName('as_address1').length > 0 && document.getElementsByName('as_address1')[0].value == ''){
			setRegError('as_address1');
			vInner2 = false;
			ok = false;
		}
	}
	if(document.getElementsByName('itemCity')) {
		if(document.getElementsByName('itemCity').length > 0 && document.getElementsByName('itemCity')[0].value == ''){
			setRegError('itemCity');
			vInner3 = false;
			ok = false;
		}
	}
	if(ok){
		hiddenFloatingDiv();
		
		try {
			if(userLevel == 'ADV') {//solo para avanzados, invisible el arbol para IE6
				showTreeCateg();
			}
		}catch(e) {}//no es un usuario avanzado
		
		isLoad = true;
	}
}

var vInner1 = true;
var vInner2 = true;
var vInner3 = true;

function setRegError(err){
  vInner = false;
  if(('as_doc_number' == err && vInner1) || ('as_address1' == err && vInner2) || ('itemCity' == err && vInner3))
    vInner = true;
	
  for(key in regErrors){
    if(key == err){
      if($(key+'ErrTxt')){
        if($(key+'ErrImg')){
          if(vInner)
            $(key+'ErrImg').innerHTML = imgRegError;
          $(key+'ErrImg').style.display = 'block';
        }
        if(vInner)
          $(key+'ErrTxt').innerHTML = regErrors[key];
        $(key+'ErrTxt').style.display = 'block';
      }
    }
  }
}

/*-------- IMPORT FROM ( Name [ pdp/CtlgPhotosView.js ], Type [ WebComponetFile  ] ) --------*/
var uploading = false;

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 showLoadingGif(i){
	k = i+1;
	gif = document.getElementById("loadingGif"+k);
	imgPrev = document.getElementById("imagePreview"+i);
	pos = getAbsoluteElementPosition("imagePreview"+i);
	plustop = (imgPrev.height/2) - (gif.height/2);
	plusleft = (imgPrev.width/2) - (gif.width/2);
	gif.style.top = pos.top + plustop;
	gif.style.left = pos.left + plusleft;
	gif.style.display = "block";
}
function disablePicLoader(i){
	k = i+1;
	divDimmerPics = document.getElementById('dimmerPics'+k);
	pos = getAbsoluteElementPosition("imagePreview"+i);
	imgPrev = document.getElementById("imagePreview"+i);
	lwidth = imgPrev.width;
	lheight = imgPrev.height;
	if(divDimmerPics == null){
		element = document.createElement("div");
		element.style.width = lwidth;
		element.style.height = lheight;
		element.style.top = pos.top;
		element.style.left = pos.left;
		element.id="dimmerPics"+k;
		element.className="dimmerPics";
		document.getElementsByTagName("body")[0].appendChild(element);
	}else{
		element.style.top = pos.top;
		element.style.left = pos.left;
		divDimmerPics.style.display = "block";
	}
	showLoadingGif(i);
}

function showErrorMsj(){
	isUploadingPic = false;
	
	picErr = document.getElementById("picErr");
	pos = getAbsoluteElementPosition("picsTable");
	picsTable = document.getElementById("picsTable");
	imgPrev = document.getElementById("imagePreview0");
	tableHeight = imgPrev.offsetHeight;
	tableWidth = picsTable.offsetWidth;
	
	plusTop = (tableHeight - getDim(picErr.style.height))/2;
	plusLeft = (tableWidth - getDim(picErr.style.width))/2;
	
	picErr.style.top = pos.top + plusTop;
	picErr.style.left = pos.left + plusLeft;
	
	picErr.style.display = "block";
}

function hideErrorMsj(){
	picErr.style.display = "none";
}

function validePicFormats(i){
	lFile = document.getElementById("uploadfile"+i).value;
	lFileLength = lFile.length;
	fileExt = lFile.substring(lFileLength-4).toUpperCase();
	if(fileExt == '.JPG' ||  fileExt == '.JPEG' ||  fileExt == '.PNG' ||  fileExt == '.GIF')
		return true;
		
	showErrorMsj();
	return false;
}

var isUploadingPic = false;
var cantEncoledPics = 0;
var encoledPics = new Array();
var notDisPicLoader = false;

function prepareUploadPics(i){
	if(!validePicFormats(i))
		return;
	
	disablePicLoader(i-1);
	
	hideBottomActions();
	
	if(isUploadingPic){
		encoledPics.push(i);
		cantEncoledPics++;
	}else{
		isUploadingPic = true;
		
		if(cantEncoledPics>0){
			encoledPics.splice(0,1);
			cantEncoledPics--;
		}
		
		var iform = document.getElementById("uploadIframeForm"+i);
	
		var siteID = document.getElementById("as_site_id");
		var	itemID = document.getElementById("as_item_id");
		var	imagePath = document.getElementById("as_image_path");
	
		iform.act.value = "";
	
		iform.as_site_id.value = siteID.value;
		iform.as_item_id.value = itemID.value;
		iform.as_image_path.value = imagePath.value;
	
		iform.submit();
	}
}
function uploadNextEncoledPic(){
	isUploadingPic = false;
	if(cantEncoledPics>0){
		prepareUploadPics(encoledPics[0]);
	}else{
		hideDimmersPicsLoading();
	}
}
function performActionPic(i, action){
	var iform = document.getElementById("uploadIframeForm"+i);
	
	var file = document.getElementById("uploadfile"+i);
	
	var siteID = document.getElementById("as_site_id");
	var itemID = document.getElementById("as_item_id");
	var imagePath = document.getElementById("as_image_path");
	var categID = document.getElementById("as_categ_id");
	
	if(action == "del") file.value = "";
	
	iform.act.value = action;
	
	iform.as_site_id.value = siteID.value;
	iform.as_item_id.value = itemID.value;
	iform.as_image_path.value = imagePath.value;
	iform.as_categ_id.value = categID.value;
	
	iform.submit();
}
function hideDimmersPicsLoading(){
	for(i=1; i<=6; i++){
		if(document.getElementById("dimmerPics"+i) && document.getElementById("loadingGif"+i)){
			document.getElementById("dimmerPics"+i).style.display = "none";
			document.getElementById("loadingGif"+i).style.display = "none";
		}
	}
}
function hideBottomActions(){
	for(i=1; i<=6; i++){
		if(document.getElementById("aMoveF"+i))
			document.getElementById("aMoveF"+i).style.display = "none";
		if(document.getElementById("aMoveB"+i))
			document.getElementById("aMoveB"+i).style.display = "none";
		if(document.getElementById("delete"+i))
			document.getElementById("delete"+i).style.display = "none";
	}
}
function addRandom(tagA){
	tagA.href+='&rand='+Math.random()+'addRnd';
}

/*-------- IMPORT FROM ( Name [ pdp/pdpScripts.js ], Type [ WebComponetFile  ] ) --------*/
/* PDP 15-01-2008 9:33 */ 

//flechas para mover los frames



function shiftRight(name){
		
		(document.getElementById(name+'Desplazadas').value) ++;
		
	
		//OCULTO
		if (document.getElementById('div'+name+(((parseInt(document.getElementById(name+'Desplazadas').value)-1)*5)+1)) != null){
			document.getElementById('div'+name+(((parseInt(document.getElementById(name+'Desplazadas').value)-1)*5)+1)).style.display = 'none';
		}
		if (document.getElementById('div'+name+(((parseInt(document.getElementById(name+'Desplazadas').value)-1)*5)+2)) != null){
			document.getElementById('div'+name+(((parseInt(document.getElementById(name+'Desplazadas').value)-1)*5)+2)).style.display = 'none';
		}
		if (document.getElementById('div'+name+(((parseInt(document.getElementById(name+'Desplazadas').value)-1)*5)+3)) != null){
			document.getElementById('div'+name+(((parseInt(document.getElementById(name+'Desplazadas').value)-1)*5)+3)).style.display = 'none';
		}
		if (document.getElementById('div'+name+(((parseInt(document.getElementById(name+'Desplazadas').value)-1)*5)+4)) != null){
			document.getElementById('div'+name+(((parseInt(document.getElementById(name+'Desplazadas').value)-1)*5)+4)).style.display = 'none';
		}
		if (document.getElementById('div'+name+(((parseInt(document.getElementById(name+'Desplazadas').value)-1)*5)+5)) != null){
			document.getElementById('div'+name+(((parseInt(document.getElementById(name+'Desplazadas').value)-1)*5)+5)).style.display = 'none';
		}	
		
	
		//MUESTRO
		if (document.getElementById('div'+name+((document.getElementById(name+'Desplazadas').value*5)+1)) != null){
			document.getElementById('div'+name+((document.getElementById(name+'Desplazadas').value*5)+1)).style.display = 'block';
			document.getElementById(name+'Show').value = (document.getElementById(name+'Desplazadas').value*5)+1;
		}
		
		if (document.getElementById('div'+name+((document.getElementById(name+'Desplazadas').value*5)+2)) != null){
			document.getElementById('div'+name+((document.getElementById(name+'Desplazadas').value*5)+2)).style.display = 'block';
			document.getElementById(name+'Show').value = (document.getElementById(name+'Desplazadas').value*5)+2;
		}
		if (document.getElementById('div'+name+((document.getElementById(name+'Desplazadas').value*5)+3)) != null){
			document.getElementById('div'+name+((document.getElementById(name+'Desplazadas').value*5)+3)).style.display = 'block';
			document.getElementById(name+'Show').value = (document.getElementById(name+'Desplazadas').value*5)+3;		
		}
		if (document.getElementById('div'+name+((document.getElementById(name+'Desplazadas').value*5)+4)) != null){
			document.getElementById('div'+name+((document.getElementById(name+'Desplazadas').value*5)+4)).style.display = 'block';
			document.getElementById(name+'Show').value = (document.getElementById(name+'Desplazadas').value*5)+4;
		}
		if (document.getElementById('div'+name+((document.getElementById(name+'Desplazadas').value*5)+5)) != null){
			document.getElementById('div'+name+((document.getElementById(name+'Desplazadas').value*5)+5)).style.display = 'block';
			document.getElementById(name+'Show').value = (document.getElementById(name+'Desplazadas').value*5)+5;
		}

		
		document.getElementById('shift'+name+'Left').style.display = 'block';
		if(document.getElementById(name+'Total').value - document.getElementById(name+'Show').value == 0 ){
			document.getElementById('shift'+name+'Right').style.display = 'none';
		}	
}


function shiftLeft(name){
	
	
		(document.getElementById(name+'Desplazadas').value) --;

					 
		//OCULTO
		if (document.getElementById('div'+name+(((parseInt(document.getElementById(name+'Desplazadas').value)+1)*5)+1)) != null){
			document.getElementById('div'+name+(((parseInt(document.getElementById(name+'Desplazadas').value)+1)*5)+1)).style.display = 'none';
		}
		if (document.getElementById('div'+name+(((parseInt(document.getElementById(name+'Desplazadas').value)+1)*5)+2)) != null){
			document.getElementById('div'+name+(((parseInt(document.getElementById(name+'Desplazadas').value)+1)*5)+2)).style.display = 'none';
		}
		if (document.getElementById('div'+name+(((parseInt(document.getElementById(name+'Desplazadas').value)+1)*5)+3)) != null){
			document.getElementById('div'+name+(((parseInt(document.getElementById(name+'Desplazadas').value)+1)*5)+3)).style.display = 'none';
		}
		if (document.getElementById('div'+name+(((parseInt(document.getElementById(name+'Desplazadas').value)+1)*5)+4)) != null){
			document.getElementById('div'+name+(((parseInt(document.getElementById(name+'Desplazadas').value)+1)*5)+4)).style.display = 'none';
		}
		if (document.getElementById('div'+name+(((parseInt(document.getElementById(name+'Desplazadas').value)+1)*5)+5)) != null){
			document.getElementById('div'+name+(((parseInt(document.getElementById(name+'Desplazadas').value)+1)*5)+5)).style.display = 'none';
		}	
		
		
		//MUESTRO
		if (document.getElementById('div'+name+((document.getElementById(name+'Desplazadas').value*5)+1)) != null){
			document.getElementById('div'+name+((document.getElementById(name+'Desplazadas').value*5)+1)).style.display = 'block';
			document.getElementById(name+'Show').value = (document.getElementById(name+'Desplazadas').value*5)+1;
		}
		
		if (document.getElementById('div'+name+((document.getElementById(name+'Desplazadas').value*5)+2)) != null){
			document.getElementById('div'+name+((document.getElementById(name+'Desplazadas').value*5)+2)).style.display = 'block';
			document.getElementById(name+'Show').value = (document.getElementById(name+'Desplazadas').value*5)+2;
		}
		if (document.getElementById('div'+name+((document.getElementById(name+'Desplazadas').value*5)+3)) != null){
			document.getElementById('div'+name+((document.getElementById(name+'Desplazadas').value*5)+3)).style.display = 'block';
			document.getElementById(name+'Show').value = (document.getElementById(name+'Desplazadas').value*5)+3;		
		}
		if (document.getElementById('div'+name+((document.getElementById(name+'Desplazadas').value*5)+4)) != null){
			document.getElementById('div'+name+((document.getElementById(name+'Desplazadas').value*5)+4)).style.display = 'block';
			document.getElementById(name+'Show').value = (document.getElementById(name+'Desplazadas').value*5)+4;
		}
		if (document.getElementById('div'+name+((document.getElementById(name+'Desplazadas').value*5)+5)) != null){
			document.getElementById('div'+name+((document.getElementById(name+'Desplazadas').value*5)+5)).style.display = 'block';
			document.getElementById(name+'Show').value = (document.getElementById(name+'Desplazadas').value*5)+5;
		}

		
		document.getElementById('shift'+name+'Right').style.display = 'block';
		if(document.getElementById(name+'Desplazadas').value == 0 ){
			document.getElementById('shift'+name+'Left').style.display = 'none';
		}
	
	

}

//Paginado solapa opiniones

function showPage(pageNum){
	document.getElementById('pagina').value = pageNum;
	document.getElementById('page').submit();
}

function nextPage(){
	document.getElementById('pagina').value ++;
	document.getElementById('page').submit();	
}

function prevPage(){
	document.getElementById('pagina').value --;
	document.getElementById('page').submit();	
}



//mostrar u ocultar especificaciones y comentarios sobre opiniones
function showGroup(clasifName){
	if (document.getElementById(clasifName).style.display == 'block'){
		document.getElementById(clasifName).style.display = 'none';
		document.getElementById('img'+clasifName).src = 'http://www.mercadolibre.com.ar/org-img/ssh/mas.png';
		document.getElementById('img'+clasifName).alt = 'Expandir Grupo';
	}else{
		document.getElementById(clasifName).style.display = 'block';
		document.getElementById('img'+clasifName).src = 'http://www.mercadolibre.com.ar/org-img/ssh/menos.png';
		document.getElementById('img'+clasifName).alt = 'Contraer Grupo';
	}
}

function showComm(id){
	if (document.getElementById(id).style.display == 'block'){
		document.getElementById(id).style.display = 'none';
		document.getElementById('img'+id).src = 'http://www.mercadolibre.com.ar/org-img/ssh/mas.png';
		document.getElementById('img'+id).alt = 'Ver comentarios';
		document.getElementById('comentario'+id).innerHTML = 'Leer';
	}else{
		document.getElementById(id).style.display = 'block';
		document.getElementById('img'+id).src = 'http://www.mercadolibre.com.ar/org-img/ssh/menos.png';
		document.getElementById('img'+id).alt = 'Ocultar comentarios';
		document.getElementById('comentario'+id).innerHTML = 'Ocultar';
	}
}

function showCommPt(id){
	if (document.getElementById(id).style.display == 'block'){
		document.getElementById(id).style.display = 'none';
		document.getElementById('img'+id).src = 'http://www.mercadolibre.com.ar/org-img/ssh/mas.png';
		document.getElementById('img'+id).alt = 'Leia os comentários';
		document.getElementById('comentario'+id).innerHTML = 'Leia';
	}else{
		document.getElementById(id).style.display = 'block';
		document.getElementById('img'+id).src = 'http://www.mercadolibre.com.ar/org-img/ssh/menos.png';
		document.getElementById('img'+id).alt = 'Ocultar os comentários';
		document.getElementById('comentario'+id).innerHTML = 'Ocultar';
	}
}

//cambiar el orden
function changeOrder(order){
	document.getElementById('hidOrder').value = order;
	this.form.submit();
	return false;
}


var actual = 1;
var imgTotal = 10;
function loadImage(nroFoto){
	document.getElementById('divimg'+actual).className = ''; 
	document.getElementById('img'+actual).className = '';
	actual = nroFoto;
	document.getElementById('mainImg').src = document.getElementById('src'+actual).value;
	document.getElementById('mainImg').alt = document.getElementById('hid'+actual).value;
	document.getElementById('mainImg').title = document.getElementById('hid'+actual).value;
	document.getElementById('divimg'+actual).className = 'imagenSeleccionada';
	document.getElementById('divMainImg').style.display = 'block';
	document.getElementById('divVideo').innerHTML = '<div id="ytapiplayer"></div>';
	document.getElementById('divVideo').style.display = 'none';
}

/* loadImage vieja
function loadImage(nroFoto){
	document.getElementById('divimg'+actual).className = ''; 
	document.getElementById('img'+actual).className = ''; 
	actual = nroFoto;
	document.getElementById('mainImg').src = document.getElementById('src'+actual).value;
	document.getElementById('divimg'+actual).className = 'imagenSeleccionada';
	
}
*/

function loadVideo(nroFoto){
	
	document.getElementById('divVideo').style.display = 'block';
	document.getElementById('divimg'+actual).className = ''; 
	document.getElementById('img'+actual).className = '';
	actual = nroFoto;
	showVideo(document.getElementById('src'+actual).value);
	//showLoadingVideo();
	document.getElementById('divimg'+actual).className = 'imagenSeleccionada';
	document.getElementById('divMainImg').style.display = 'none';
	
}
/*
function showLoadingVideo() {
vidCont = document.getElementById("ytapiplayer");
dimmer = document.getElementById("videosDimmerLoading");
dimmer.style.top = vidCont.style.top;
dimmer.style.left = vidCont.style.left;
dimmer.style.display = "block";

}
function onYouTubePlayerReady() {
	document.getElementById('divVideo').style.display = 'block';
dimmer = document.getElementById("videosDimmerLoading");
dimmer.style.display = 'none';
document.getElementById("ytapiplayer").style.visibility = 'visible';
}
*/

function opacarImagen(imagen){
	var img = document.getElementById('img'+imagen);
	if(img != document.getElementById('img'+actual)){
		img.className = 'opacarImagen';
	}
}

function desOpacarImagen(imagen){
	var img = document.getElementById('img'+imagen);
	if(img != document.getElementById('img'+actual)){
		img.className = 'desOpacarImagen';
	}
}
	  

      var params = { allowScriptAccess: "always", bgcolor: "#cccccc", wmode: "transparent"};
      var atts = { id: "myytplayer"};
      function showVideo(id){
      	swfobject.embedSWF("http://www.youtube.com/v/" + id + "&rel=0&hl=es&enablejsapi=1&playerapiid=ytplayer", "ytapiplayer", "280", "275", "8", null, null, params, atts);
 			}
                           
var loginHwnd;
//var actionForm = '/jm/catalogPdpImageLoader';


function prepareUploadPics2(i){

	
	var iform = document.getElementById("uploadIframeForm"+i);
		
		var customKey = "comu";
		var picnum = "-1";
	  var prodID = parent.document.getElementById('prodID').value;
           	
    iform.act.value = "";
		iform.enctype = "multipart/form-data";
		iform.encoding = "multipart/form-data";
		iform.customkey.value = customKey;
        
    document.getElementById('loadingGif1').style.display = 'block';
    document.getElementById('errorImg').style.display ='none';
		document.getElementById('errorTitle').style.display = 'none';
    
    iform.action = actionForm;
		iform.action = iform.action+"?customkey="+customKey+"&picnum="+picnum+"&prodID="+prodID+"&fromPdp=Y";
    iform.submit();
	}
	
function checkUploadImage(){
		if (hasHashPdp()) {
				showRegSeller();
		} else {
	
				loginPic();		
	
		}
}

function hasHashPdp() {
	 if (getCookieValue('orgpago')!=null && getCookieValue('orgpago').length>1){
		return true;
	}else{
	  return false;
	}
}

function loginPic(){
	if (existHash){
		showRegSeller();
	}
	if(loginHwnd && !loginHwnd.closed){
		loginHwnd.focus();
		return;
	}
	loginHwnd = wOpenPic("http://"+window.location.host+"/jm/loginDwr?urlFrom=http://"+window.location.host+"/jm/loginDwr?function=closeAndShowRegSeller();//", "", 640, 360, "no", "");
}


function wOpenPic(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

	loginHwnd = window.open(pURL,pName,xSettings);
	if(loginHwnd.window.focus){loginHwnd.window.focus();}
	if(text != "") {
		loginHwnd.document.write(text);
		loginHwnd.document.close();		
	}

	return loginHwnd;
}

function showRegSeller()
{
	
	var regDiv = document.getElementById(gDivID);
	
	auxDivHeight = getDimension(regDiv.style.height);
	auxDivWidth = getDimension(regDiv.style.width);
	/*
	auxTop = getDivTop(gDivID);
	auxLeft = getDivLeft(gDivID);
	
	
	auxTop = '300px';
	auxLeft = 'auto';
	
	displayFloatingDiv(gDivID, auxLeft, auxTop, auxDivHeight, auxDivWidth);
	*/
	displayFloatingDiv(gDivID, auxDivHeight, auxDivWidth);
}

function closeAndShowRegSeller () {
	existHash = hasHashPdp();
	if(loginHwnd && !loginHwnd.closed){
		window.setTimeout('showRegSeller()', 0);
	}
	loginHwnd.close();
	showRegSeller();
}

function delPic(){
	document.getElementById("imagePreview0").src = "http://www.mercadolibre.com/org-img/ssh/cargar_foto_com.png";
	document.getElementById("title").value = "";
	document.getElementById("uploadfile1").value = "";
	document.getElementById("delete1").style.display="none";
	document.getElementById('loadingGif1').style.display = 'none';
}

function showErrorMsg(){
	document.getElementById('errorImg').style.display ='block';
	document.getElementById('loadingGif1').style.display = 'none';
}
function showErrorTitle(){
	document.getElementById('errorTitle').style.display = 'block';
	document.getElementById('loadingGif1').style.display = 'none';
}

function cancelPicTitle() {
        document.getElementById("imagePreview0").src = "http://www.mercadolibre.com/org-img/ssh/cargar_foto_com.png";
				document.getElementById("title").value = "";
				document.getElementById("uploadfile1").value = "";
				document.getElementById('loadingGif1').style.display = 'none';
				document.getElementById('errorImg').style.display ='none';
				document.getElementById('errorTitle').style.display = 'none';
				document.getElementById('body_counter2').innerHTML = '100';
				hiddenFloatingDiv();
}


function hiddenFloatingDiv() {
	
	document.getElementById(gDivID).style.display='none';
	document.getElementById('dimmer').style.display = 'none';
}


function savePic(){
	if(document.getElementById('title').value != null && document.getElementById('title').value != "" && document.getElementById('title').value.length > 100){
		showErrorTitle();
		return;
	}
	var iform = document.getElementById("uploadIframeForm1");
	iform.action = actionForm;
	
	var prodID = parent.document.getElementById('prodID').value;
	var titulo = parent.document.getElementById('title').value;
	var axn = "save";
	var tempFileName = document.getElementById('tempFileName').value;
	iform.action = iform.action + "?prodID="+prodID+"&accion="+axn+"&title="+titulo+"&fromPdp=Y&tempFileName="+tempFileName;
	
	iform.submit();
	

}

function displayFloatingDiv(divID, pHeight, pWidth) 
{
	sellerRegOn = true;
	//con esto acomodo los 2 divs si el usuario modifica el tamaño del navegador
	window.onresize = resizeDivs;
	createDimmerDiv();
	
	regDiv = document.getElementById(gDivID);
	/*
	regDiv.style.left = pLeft;
	regDiv.style.top = pTop;
	*/
	regDiv.style.display = 'block';
	
}



/* FUNCIONES DE MANUALES */

function checkUploadManual(){
		if (hasHashPdp()) {
				showDivManual('divMan');
		} else {
				loginMan();		
		}
}

function loginMan(){
	if (existHash){
			showDivManual('divMan');
	}
	if(loginHwnd && !loginHwnd.closed){
		loginHwnd.focus();
		return;
	}
	loginHwnd = wOpenPic("http://"+window.location.host+"/jm/loginDwr?urlFrom=http://"+window.location.host+"/jm/loginDwr?function=closeAndShowDivManual();//", "", 640, 360, "no", "");
}

function closeAndShowDivManual () {
	existHash = hasHashPdp();
	if(loginHwnd && !loginHwnd.closed){
		window.setTimeout('showDivManual("divMan")', 0);
	}
	loginHwnd.close();
	showDivManual('divMan');
}


function showDivManual(gDivID)
{
	
	parent.document.getElementById("manualErr").style.display = "none";
	parent.document.getElementById("titleErr").style.display = "none";
	
	arch1 = parent.document.getElementById("manualArchInput");
  upfile = parent.document.getElementById("manualArch");
	arch2 = parent.document.getElementById("manualArchInput2");
	arch1.style.display = "block";
  upfile.style.display = "block";
	arch2.style.display = "none";
	
	var regDiv = document.getElementById(gDivID);
	
	auxDivHeight = getDimension(regDiv.style.height);
	auxDivWidth = getDimension(regDiv.style.width);
	/*
	auxTop = getDivTop(gDivID);
	auxLeft = getDivLeft(gDivID);

	
	auxTop = '1500px';
	auxLeft = 'auto';
	
	displayFloatingDivMan(gDivID, auxLeft, auxTop, auxDivHeight, auxDivWidth);
	*/
	displayFloatingDivMan(gDivID, auxDivHeight, auxDivWidth);
}

function displayFloatingDivMan(divID, pHeight, pWidth)
{
	sellerRegOn = true;
	//con esto acomodo los 2 divs si el usuario modifica el tamaño del navegador
	window.onresize = resizeDivs;
	createDimmerDiv();
	
	regDiv = document.getElementById(divID);
/*	regDiv.style.left = pLeft;
	regDiv.style.top = pTop;*/
	regDiv.style.display = 'block';
}

var totalWidth;
function createDimmerDiv() {
	if (document.getElementById('dimmer') == null){
		element = document.createElement("div");
		getTotalWindowWidth();
		element.style.height = document.body.scrollHeight + 10 + "px";
		element.style.width = totalWidth + "px";
		element.id="dimmer";
		document.getElementsByTagName('body')[0].appendChild(element);
	}else{
		document.getElementById('dimmer').style.display = 'block';
	}
	
}


function getTotalWindowWidth() 
{
  functionSelector('totalWidth = screen.width - getHScrollBarWidth()', 
  								 'totalWidth = screen.width - 21',
  								 'totalWidth = screen.width - 21');
}

function getHScrollBarWidth()
{
	var div = document.createElement("div");
	var innerDiv = document.createElement("div");
	
	div.style.width="50px";
	div.style.height="50px";
	div.style.overflow="hidden";
	div.style.position="absolute";
	div.style.top="-200px";
	div.style.left="0px";
	
	innerDiv.style.height="100px"; 
	
	div.appendChild(innerDiv);
	document.getElementsByTagName('body')[0].appendChild(div);
	
	var w1 = innerDiv.clientWidth;
	
	div.style.overflow="scroll";
	
	var w2 = innerDiv.clientWidth;
	
	document.getElementsByTagName('body')[0].removeChild(div);	
	
	return (w1 - w2);
}


function cancelManTitle() {
        
				document.getElementById("titulo").value = "";
				document.getElementById("fileField").value = "";
				document.getElementById("body_counter3").innerHTML = '40';
				hiddenFloatingDivMan('divMan');
}

function hiddenFloatingDivMan(divId) {

	sellerRegOn = false;
	document.getElementById(divId).style.display='none';
	document.getElementById('dimmer').style.display = 'none';

}



function uploadManual2(){

	parent.document.getElementById("manualErr").style.display = "none";
	parent.document.getElementById("titleErr").style.display = "none";
	if(!valideManual())
		return; 
		
	if(!valideTitle())
		return; 
	
	showLoadingManual();
	
	var iform = document.getElementById("uploadFormManual");
	var customKey = document.getElementById("customkey").value;
	iform.enctype = "multipart/form-data";
	iform.encoding = "multipart/form-data";
	iform.customkey.value = customKey;
  var product = document.getElementById("prodId").value;
  var titulo = document.getElementById("titulo").value;
  iform.action = actionFormMan;
	iform.action = iform.action+"?customkey=comu&type=M&fromPdp=Y&prodId="+product+"&title="+titulo;
        
	iform.submit();
	
	//window.location.reload();
	

	
	
}





function textCounter(field, countfield, maxlimit) {
	var xA;
	var xB;
	
	//Limitar la cantidad de caracteres
	xB = document.getElementById(field);

	if (xB.value.length > maxlimit)  {// if too long...trim it!
	   xB.value = xB.value.substring(0, maxlimit);
	}else{
	   // otherwise, update 'characters left' counter
	   xA = document.getElementById(countfield);
	   xA = xA.firstChild;
	   xA.nodeValue = maxlimit - xB.value.length;
	}
}






function valideManual() {
 	lFile = document.getElementById("fileField").value;
	lFileLength = lFile.length;
	fileExt = lFile.substring(lFileLength-4).toUpperCase();
	if(fileExt == '.PDF')
		return true;
		
	showErrorMsjManual();
	return false
}


function valideTitle() {
 	var titulo = document.getElementById("titulo").value;

	if(titulo.length > 0 && titulo.length < 41){
		return true;
	}
	showErrorMsjTitle();
	return false
}

function showErrorMsjTitle(){
  
	var manualErr = parent.document.getElementById("titleErr");
        //alert(manualErr);
	var pos = getAbsoluteElementPosition("LabelArchivo");
	manualErr.style.top = pos.top;
	manualErr.style.left = pos.left + 40;
	manualErr.style.display = "block";

}


function showErrorMsjManual(){

  	var arch1 = document.getElementById("manualArchInput");
        var upfile = document.getElementById("manualArch");
	var arch2 = document.getElementById("manualArchInput2");
	arch1.style.display = "block";
        upfile.style.display = "block";
	arch2.style.display = "none";
  
	var manualErr = parent.document.getElementById("manualErr");
        //alert(manualErr);
        
     
	var pos = getAbsoluteElementPosition("LabelArchivo");

	manualErr.style.top = pos.top;
	manualErr.style.left = pos.left + 40;
	
	manualErr.style.display = "block";

}

function showLoadingManual() {
	arch1 = parent.document.getElementById("manualArchInput");
        upfile = parent.document.getElementById("manualArch");
	arch2 = parent.document.getElementById("manualArchInput2");
	arch1.style.display = "none";
        upfile.style.display = "none";
	arch2.style.display = "block";

}

function manualLoadSuccess() {
	arch2 = document.getElementById("manualArchInput2");
	arch3 = document.getElementById("manualArchInput3");
	arch2.style.display = "none";
	arch3.style.display = "block";
}

function initManualLoaderButtons(){
	pos = getAbsoluteElementPosition('LabelArchivo');
	upFile = document.getElementById('manualArch');
	tituloInputPos = getAbsoluteElementPosition('titulomanual');
	upFile.style.top = pos.top;
	upFile.style.left = tituloInputPos.left;
}


function manualLoadSuccess() {
	arch2 = document.getElementById("manualArchInput2");
	arch3 = document.getElementById("manualArchInput3");
	arch2.style.display = "none";
	arch3.style.display = "block";
}

function getAbsoluteElementPosition(aName) {
  element = document.getElementById(aName);
  if(!element)
  	element = document.getElementsByName(aName)[0];
  
  if (!element) return { top:0,left:0 };
  
  var y = 0;
  var x = 0;
  while (element.offsetParent) {
    x += element.offsetLeft;
    y += element.offsetTop;
    element = element.offsetParent;
  }
  return {top:y,left:x};
} 


function manualLoadErr(msg) {
arch2 = document.getElementById("manualArchInput2");
arch2.style.display = "none";
arch3 = document.getElementById("manualArchInput3");
arch3.innerHTML = msg;
arch3.style.display = "block";
}



//////////////////////////AGREGO CODIGO DE SEARCH PARA EL BUSCADOR///////////////////////////////////////



/////////////////////////////////////////////////////////////////


var urlDflt ='http://www.mercadolibre.com.ar/argentina/ml/';
var scriptName = '/argentina/ml/';
var siteId = 'MLA';
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 innerSearch(){

	var word = document.getElementById('as_inner_word').value;

	setCookie("ml_list","searching");	
	setCookie('LAST_SEARCH', word, null);	
	
	var categID = '';
	var check=document.getElementById('categ_check');
	if (check != null && check.checked){
		categID = document.getElementById('categ_check').value;
	}

	addQSParamPdp('as_word', word);
	if( getCookieValue('pr_categ') == 'AD' ){
		addQSParamPdp('as_pr_categ_id','AD');
	}else{
		addQSParamPdp('as_pr_categ_id','');
	}
	addQSParamPdp('as_desde', '1');
	addQSParamPdp('as_order_id', '');
	addQSParamPdp('as_all', '');
	addQSParamPdp('as_eshop_filter','');
	addQSParamPdp('as_filter_id','');
	addQSParamPdp('as_filtro_id','');
	addQSParamPdp('as_filtro_id2','');
	addQSParamPdp('as_filtro_id3','');
	addQSParamPdp('bnr','');	
	addQSParamPdp('as_search_both','');
	addQSParamPdp('as_nickname','');
	addQSParamPdp('as_cust_id','');
	addQSParamPdp('marca','');
	addQSParamPdp('modelo','');
	addQSParamPdp('as_year_max','');
	addQSParamPdp('as_year_min','');
	addQSParamPdp('noQCat','');
	addQSParamPdp('as_pcia_id','');
	addQSParamPdp('as_other_filter_id','');
	addQSParamPdp('as_item_type_id','');
	addQSParamPdp('as_auct_type_id','');
	addQSParamPdp('as_price_max','');
	addQSParamPdp('as_price_min','');
	addQSParamPdp('as_product_id','');
	addQSParamPdp('as_cant_puertas','');
	addQSParamPdp('as_combustible','');
	addQSParamPdp('as_kms_max','');
	addQSParamPdp('as_kms_min','');

	if (categID == ''){
		addQSParamPdp('as_meta_categ_id','');
	}
	goPdp('as_categ_id',categID);

}
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 getUrlqueryStringPdp(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);
	urlqueryStringPdp= self.location.search;
	try{
		if(oldUrl!=null){
			urlPath= getUrlPath(oldUrl);
			urlqueryStringPdp= getUrlqueryStringPdp(oldUrl);
		}
	}
	catch(Exception){
	}


	if (ck==null||ck.length < 4 ){
		document.write("<a target=\"_top\" href=\"/jm/login?url="+escape(urlPath)+escape(urlqueryStringPdp)+"\" 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 queryStringPdp = window.location.search;
var queryStringPdp = "";//oldUrl.substr(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 getURLPdp(){
    //return location.pathname+queryStringPdp;
    return oldPathPdp+queryStringPdp;
}
function getTrackURL(){
    return (location.pathname+queryStringPdp).replace(/&/gi, "\$\$\$\$");
}
function addQSParamPdp(par, newValue){		
    //si no esta, lo agrego
    pos = queryStringPdp.indexOf(par+"=");    
	//El escape de JS no contempla el +.
	newValue = escape(newValue);
	if ( par == "as_word" ){
		newValue = newValue.replace(/\+/gi, "%2B");
	}    
    if (pos == NOT_FOUND){
    	//solo agrego si hay valor    	
		if ( newValue.length > 0 ) {
			if (queryStringPdp.indexOf("?")==NOT_FOUND)
				queryStringPdp	+= "?";
			else
				queryStringPdp	+= "&";				
			queryStringPdp	+= par+"="+newValue;			
		}
    } else {
        //si esta, lo reemplazo        
        start = pos-1;
        end = queryStringPdp.indexOf("&", pos+1);

		if (end == NOT_FOUND)
		    toReplace = queryStringPdp.substr(start);
		else
		    toReplace = queryStringPdp.substr(start, end-start);	
		if ( newValue.length > 0 )			
			newString = toReplace.substr(0,1)+par+"="+newValue;
		else
			newString = "";	
	if (queryStringPdp.indexOf("?"+par)!=-1 && newString == ""){		
		queryStringPdp="?"+queryStringPdp.replace(toReplace+"&",newString);		
	}else{
        	queryStringPdp = queryStringPdp.replace(toReplace,newString);
        }        
    }
}
function goPdp(par, newValue){
	addQSParamPdp("as_desde", "");
	addQSParamPdp("as_qshow", "");
	addQSParamPdp(par, newValue);
	location.href = getURLPdp();
}

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 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);
	}
}


function hasScrolled(){
	var offset = 0;
	if (document.body.scrollTop){
		alert("You've scrolled to " + document.body.scrollTop + " pixels.");
		offset = document.body.scrollTop;
	}else{
		alert ("You've scrolled to " + window.pageYOffset + " pixels.");
		offset = window.pageYOffset;
	}
	if(offset>90){
		return true;	
	}else{
		return false;
	}
}

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');
		//createTag('http://www.mercadolibre.com.ar/org-img/jsapi/escalator/bannerDivs.js','js');
	}
}

window.onscroll  = realignOpenCombo;
window.onresize  = realignOpenCombo;


function functionSelector(f_if_NonIE, f_if_IE6, f_if_IE4)
{
  if( typeof( window.innerWidth ) == 'number' ) {
    //Execute if Non-IE (Netscape Compliant)
    return(eval(f_if_NonIE));
    
  } else if( document.documentElement && document.documentElement.clientWidth) {
    //Execute if IE 6+ in 'standards compliant mode'
    return(eval(f_if_IE6));
    
  } else if( document.body && document.body.clientWidth) {
    //Execute if IE 4 compatible (DOM Compliant)
    return(eval(f_if_IE4));
  }
}




/* -> LLR - Javascript ayuda puntaje reviews */
var intervalID;
var helpObj = null;
var canBeHide = false;



//Vars para Help de Medals
		var helpPop;
		var baseT;
		var baseL;
		var popY;
		var popX;
		var hideFlag = false;
// Listo


function showRvwHelp(obj) {
            hideHelp();
            var allDivs = obj.getElementsByTagName("DIV");


            for (i=0; i < allDivs.length; i++) {
                        if (allDivs[i].name != null &&      allDivs[i].name ==  "attr_help_text") {
                                   helpObj = allDivs[i];
                        }
            }
            if (helpObj == null) {
                        helpObj = allDivs.namedItem("attr_help_text");
            }
            if (helpObj != null) {
                helpObj.style.visibility = 'visible'; 
            }
}

document.onclick = hideHelp;

function delayHide( millis ){
	if (millis == null) millis = 1000;

	deleteDelayHide();
	intervalID = setInterval('hideHelp();', millis);
}

		

function deleteDelayHide(){
	window.clearInterval( intervalID );
}

function donothing() {
}
		

function hideHelp(){
	if(helpObj!=null){
		if (canBeHide) {
			helpObj.style.visibility = 'hidden';			
			helpObj = null;
			canBeHide = false;
		} else {
			canBeHide = true;
		}
	}	
	
	
	
	
	
	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;
			}

	
	
	
	
}


	

/* <- LLR - Javascript ayuda puntaje reviews */

 /* Logout */

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\">Salir</a></div>");
	}
}




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 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 hasHash() {
	if (getCookieValue('orgpago')!=null && getCookieValue('orgpago').length>1){
		
				return true;
		
			}else{
		
			  return false;
		
			}
		
}


/* LogOut */




















	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;
                                
                                popX += 183;
                                popY -= 40;
			} else { // Netscape, etc.
				popX = clickevent.clientX;
				popY = clickevent.clientY;
				baseT = window.pageYOffset
				baseL = window.pageXOffset
                                popX += baseL;
                                popY +=baseT;
                                
                                popX += 99;
                                popY -= 21;
                                
			}
		
			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;
		}



function set_order(){	
newOrder=document.getElementById("reviews_order")[document.getElementById("reviews_order").selectedIndex].value;

	newOrder = (newOrder=="DESTACADOS"?"":newOrder);

	go("reviews_order", newOrder); 
}

function go(par, newValue){
	addQSParam("from", "");
	addQSParam(par, newValue);
	location.href = getURL();

}

var queryString = oldUrl.substr(oldUrl.indexOf("?"));
var oldPath = oldUrl.substr(0,oldUrl.indexOf("?"));
var NOT_FOUND = -1;
function addQSParam(par, newValue){

    //si no esta, lo agrego
    pos = queryString.indexOf(par+"=");
    if (pos == NOT_FOUND){

        //solo agrego si hay valor
                if ( newValue.length > 0 ) {
                        if (queryString.indexOf("?")==NOT_FOUND)
                                queryString     += "?";
                        else
                                queryString     += "&";

                        queryString     += par+"="+escape(newValue);
                }

    } else {
        //si esta, lo reemplazo
        start = pos-1;
        end = queryString.indexOf("&", pos+1);

                if (end == NOT_FOUND)
                    toReplace = queryString.substr(start);
                else
                    toReplace = queryString.substr(start, end-start);

                if ( newValue.length > 0 )
                        newString = toReplace.substr(0,1)+par+"="+escape(newValue);
                else
                        newString = "";

        queryString = queryString.replace(toReplace,newString);
    }
}

function getURL(){
    return oldPath+queryString;
}

function goRvwOrder(par, newValue){
addQSParam("from", "");
addQSParam(par, newValue);
location.href = getURL() + "#tab";

}

function openFipe(){
	var link = getBase(document.getElementsByTagName('base')[0].href)+ '/jm/ml.track.me?k1=GUIA&k2=MLB_MOT_FIPE&k3=PDP_MLB&go=' +'/jm/ml.motors.fipeBrasilSearch.fipeBrasilSearchController';
	var w = 650;
	var h = 380;
	var xLeft =(screen.width)?(screen.width-w)/2:0;
	var xTop =(screen.height)?(screen.height-h)/2:0;
	var xSettings = 'height='+h+',width='+w+',top='+xTop+',left='+xLeft+',scrollbars=no';
	var hwnd = window.open(link,'',xSettings);
	if(hwnd.window.focus){hwnd.window.focus();}
}


/*-------- IMPORT FROM ( Name [ apiCookies.js ], Type [ WebComponetFile  ] ) --------*/
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+"'>";
}	

/*-------- IMPORT FROM ( Name [ pdp/ReviewDwr.js ], Type [ WebComponetFile  ] ) --------*/
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

	loginHwnd = window.open(pURL,pName,xSettings);
	if(loginHwnd.window.focus){loginHwnd.window.focus();}
	if(text != "") {
		loginHwnd.document.write(text);
		loginHwnd.document.close();
	}
	return loginHwnd;
}

function login(reviewID,vote){
	if (existHash){
		voteReview(reviewID,vote);
		return;
	}
	if(loginHwnd && !loginHwnd.closed){
		loginHwnd.focus();
		return;
	}
	loginHwnd = wOpen("http://"+window.location.host+"/jm/loginDwr?urlFrom=http://"+window.location.host+"/jm/loginDwr?function=refreshFooter("+reviewID+","+vote+");//", "", 640, 360, "no", "");
}

function setFooter() {
	var txtFooter;
	for (i = 0; i<reviewIDs.length ; i++){	
		if (existHash){
			txtFooter =  $('votacion').innerHTML;
		}else{
			txtFooter =  $('notReg').innerHTML;
		}
		txtFooter = txtFooter.replace(/##REVIEW_ID##/g,reviewIDs[i]);
		DWRUtil.setValue('footerReview' + reviewIDs[i], txtFooter);
	}
}

function setReviewers() {
	ReviewsDwr.getReviewerProfile(reviewersIDs,
	  		{callback:function(dataFromServer) 
				{processProfile(dataFromServer, reviewersIDs,false)}});		
}

function processProfile(dataFromServer, spanId, isCataloguer) {
	if(isCataloguer){
	   	DWRUtil.setValue('profileCataloguer'+spanId, dataFromServer);	
    } else {
		for (var i = 0; i < reviewersIDs.length ; i++){
			DWRUtil.setValue('profile'+reviewersIDs[i], dataFromServer[i]);	
		}
    }	
}

function changeFooter (html, reviewID) {
	DWRUtil.setValue('footerReview'+reviewID, html);
}

function changeVote (data) {
	ReviewsDwr.getPoints(data,{callback:function(dataFromServer) {refreshPoints(dataFromServer, true)}});
}

function refreshPoints (data, isNewVote) {
	var label = '';
	var totalVote = data.pointsPos + data.pointsNeg;
	if (totalVote != null && totalVote != 0) {
		label = labelVotos.replace (/##VOTE_POSITIVE##/, data.pointsPos);
		label = label.replace (/##TOTAL_VOTE##/, totalVote);
		DWRUtil.setValue('votos'+data.reviewID, label);
		
		if (isNewVote) {
			label = $('tks').innerHTML;
			label = label.replace (/##VOTE_POSITIVE##/, data.pointsPos);
			label = label.replace (/##TOTAL_VOTE##/, totalVote);
			changeFooter(label,data.reviewID);		
		}
	}
	
}
var reviewVoting;
function voteReview (reviewID, vote) {
    reviewVoting = reviewID;
	if (hasHash()) {
		$('votacion'+reviewID).style.display = 'none';
		DWRUtil.setValue('footerReview'+reviewID, $('procesando').innerHTML);
		ReviewsDwr.voteReview (reviewID, vote, changeVote);		
	} else {
		login(reviewID, vote);		
	}
}

function refreshFooter (reviewID,vote) {
	existHash = hasHash();
	if(loginHwnd && !loginHwnd.closed){
		window.setTimeout('voteReview('+reviewID+','+vote+')', 0);
	}
	loginHwnd.close();
}

function handlerVcp (errorString, exception) {
	if (reviewVoting != null){
		DWRUtil.setValue('footerReview'+reviewVoting , $(error).innerHTML.replace(/<!--##MSJ_ERROR##-->/, errorString));
	} else {
		
	}
	reviewVoting = null;
}

function hasHash() {
	ck = getCookieValue("orguserid"); 
	return !(ck==null||ck.length < 4);
}


function submitSearch(){
	document.getElementById('words').value = trim(document.getElementById('words').value);
	return true;
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

/*-------- IMPORT FROM ( Name [ dwr/util.js ], Type [ WebComponetFile  ] ) --------*/
function DWRUtil() { }


DWRUtil.onReturn = function(event, action) {
if (!event) {
event = window.event;
}
if (event && event.keyCode && event.keyCode == 13) {
action();
}
};


DWRUtil.selectRange = function(ele, start, end) {
var orig = ele;
ele = $(ele);
if (ele == null) {
DWRUtil.debug("selectRange() can't find an element with id: " + orig + ".");
return;
}
if (ele.setSelectionRange) {
ele.setSelectionRange(start, end);
}
else if (ele.createTextRange) {
var range = ele.createTextRange();
range.moveStart("character", start);
range.moveEnd("character", end - ele.value.length);
range.select();
}
ele.focus();
};


DWRUtil._getSelection = function(ele) {
var orig = ele;
ele = $(ele);
if (ele == null) {
DWRUtil.debug("selectRange() can't find an element with id: " + orig + ".");
return;
}
return ele.value.substring(ele.selectionStart, ele.selectionEnd);


}


var $;
if (!$ && document.getElementById) {
$ = function() {
var elements = new Array();
for (var i = 0; i < arguments.length; i++) {
var element = arguments[i];
if (typeof element == 'string') {
element = document.getElementById(element);
}
if (arguments.length == 1) {
return element;
}
elements.push(element);
}
return elements;
}
}
else if (!$ && document.all) {
$ = function() {
var elements = new Array();
for (var i = 0; i < arguments.length; i++) {
var element = arguments[i];
if (typeof element == 'string') {
element = document.all[element];
}
if (arguments.length == 1) {
return element;
}
elements.push(element);
}
return elements;
}
}





DWRUtil.toDescriptiveString = function(data, level, depth) {
var reply = "";
var i = 0;
var value;
var obj;
if (level == null) level = 0;
if (depth == null) depth = 0;
if (data == null) return "null";
if (DWRUtil._isArray(data)) {
if (data.length == 0) reply += "[]";
else {
if (level != 0) reply += "[\n";
else reply = "[";
for (i = 0; i < data.length; i++) {
try {
obj = data[i];
if (obj == null || typeof obj == "function") {
continue;
}
else if (typeof obj == "object") {
if (level > 0) value = DWRUtil.toDescriptiveString(obj, level - 1, depth + 1);
else value = DWRUtil._detailedTypeOf(obj);
}
else {
value = "" + obj;
value = value.replace(/\/n/g, "\\n");
value = value.replace(/\/t/g, "\\t");
}
}
catch (ex) {
value = "" + ex;
}
if (level != 0)  {
reply += DWRUtil._indent(level, depth + 2) + value + ", \n";
}
else {
if (value.length > 13) value = value.substring(0, 10) + "...";
reply += value + ", ";
if (i > 5) {
reply += "...";
break;
}
}
}
if (level != 0) reply += DWRUtil._indent(level, depth) + "]";
else reply += "]";
}
return reply;
}
if (typeof data == "string" || typeof data == "number" || DWRUtil._isDate(data)) {
return data.toString();
}
if (typeof data == "object") {
var typename = DWRUtil._detailedTypeOf(data);
if (typename != "Object")  reply = typename + " ";
if (level != 0) reply += "{\n";
else reply = "{";
var isHtml = DWRUtil._isHTMLElement(data);
for (var prop in data) {
if (isHtml) {

if (prop.toUpperCase() == prop || prop == "title" ||
prop == "lang" || prop == "dir" || prop == "className" ||
prop == "form" || prop == "name" || prop == "prefix" ||
prop == "namespaceURI" || prop == "nodeType" ||
prop == "firstChild" || prop == "lastChild" ||
prop.match(/^offset/)) {
continue;
}
}
value = "";
try {
obj = data[prop];
if (obj == null || typeof obj == "function") {
continue;
}
else if (typeof obj == "object") {
if (level > 0) {
value = "\n";
value += DWRUtil._indent(level, depth + 2);
value = DWRUtil.toDescriptiveString(obj, level - 1, depth + 1);
}
else {
value = DWRUtil._detailedTypeOf(obj);
}
}
else {
value = "" + obj;
value = value.replace(/\/n/g, "\\n");
value = value.replace(/\/t/g, "\\t");
}
}
catch (ex) {
value = "" + ex;
}
if (level == 0 && value.length > 13) value = value.substring(0, 10) + "...";
var propStr = prop;
if (propStr.length > 30) propStr = propStr.substring(0, 27) + "...";
if (level != 0) reply += DWRUtil._indent(level, depth + 1);
reply += prop + ":" + value + ", ";
if (level != 0) reply += "\n";
i++;
if (level == 0 && i > 5) {
reply += "...";
break;
}
}
reply += DWRUtil._indent(level, depth);
reply += "}";
return reply;
}
return data.toString();
};




DWRUtil._indent = function(level, depth) {
var reply = "";
if (level != 0) {
for (var j = 0; j < depth; j++) {
reply += "\u00A0\u00A0";
}
reply += " ";
}
return reply;
};





DWRUtil.useLoadingMessage = function(message) {
var loadingMessage;
if (message) loadingMessage = message;
else loadingMessage = "Loading";
DWREngine.setPreHook(function() {
var disabledZone = $('disabledZone');
if (!disabledZone) {
disabledZone = document.createElement('div');
disabledZone.setAttribute('id', 'disabledZone');
disabledZone.style.position = "absolute";
disabledZone.style.zIndex = "1000";
disabledZone.style.left = "0px";
disabledZone.style.top = "0px";
disabledZone.style.width = "100%";
disabledZone.style.height = "100%";
document.body.appendChild(disabledZone);
var messageZone = document.createElement('div');
messageZone.setAttribute('id', 'messageZone');
messageZone.style.position = "absolute";
messageZone.style.top = "0px";
messageZone.style.zIndex="3"; 
messageZone.style.right = "0px";
messageZone.style.background = "#fee600";
messageZone.style.color = "#0000FF";
messageZone.style.fontFamily = "Arial,Helvetica,sans-serif";
messageZone.style.padding = "4px";
disabledZone.appendChild(messageZone);
var text = document.createTextNode(loadingMessage);
messageZone.appendChild(text);
}
else {
$('messageZone').innerHTML = loadingMessage;
disabledZone.style.visibility = 'visible';
}
});
DWREngine.setPostHook(function() {
$('disabledZone').style.visibility = 'hidden';
});
}





DWRUtil.setValue = function(ele, val, options) {
if (val == null) val = "";
if (options != null) {
if (options.escapeHtml) {
val = val.replace(/&/, "&amp;");
val = val.replace(/'/, "&apos;");
val = val.replace(/</, "&lt;");
val = val.replace(/>/, "&gt;");
}
}

var orig = ele;
var nodes, node, i;

ele = $(ele);

if (ele == null) {
nodes = document.getElementsByName(orig);
if (nodes.length >= 1) {
ele = nodes.item(0);
}
}
if (ele == null) {
DWRUtil.debug("setValue() can't find an element with id/name: " + orig + ".");
return;
}

if (DWRUtil._isHTMLElement(ele, "select")) {
if (ele.type == "select-multiple" && DWRUtil._isArray(val)) {
DWRUtil._selectListItems(ele, val);
}
else {
DWRUtil._selectListItem(ele, val);
}
return;
}

if (DWRUtil._isHTMLElement(ele, "input")) {
if (ele.type == "radio") {

if (nodes == null) nodes = document.getElementsByName(orig);
if (nodes != null && nodes.length > 1) {
for (i = 0; i < nodes.length; i++) {
node = nodes.item(i);
if (node.type == "radio") {
node.checked = (node.value == val);
}
}
}
else {
ele.checked = (val == true);
}
}
else if (ele.type == "checkbox") {
ele.checked = val;
}
else {
ele.value = val;
}
return;
}

if (DWRUtil._isHTMLElement(ele, "textarea")) {
ele.value = val;
return;
}



if (val.nodeType) {
if (val.nodeType == 9  ) {
val = val.documentElement;
}

val = DWRUtil._importNode(ele.ownerDocument, val, true);
ele.appendChild(val);
return;
}


ele.innerHTML = val;
};






DWRUtil._selectListItems = function(ele, val) {


var found  = false;
var i;
var j;
for (i = 0; i < ele.options.length; i++) {
ele.options[i].selected = false;
for (j = 0; j < val.length; j++) {
if (ele.options[i].value == val[j]) {
ele.options[i].selected = true;
}
}
}

if (found) return;

for (i = 0; i < ele.options.length; i++) {
for (j = 0; j < val.length; j++) {
if (ele.options[i].text == val[j]) {
ele.options[i].selected = true;
}
}
}
};






DWRUtil._selectListItem = function(ele, val) {


var found  = false;
var i;
for (i = 0; i < ele.options.length; i++) {
if (ele.options[i].value == val) {
ele.options[i].selected = true;
found = true;
}
else {
ele.options[i].selected = false;
}
}


if (found) return;

for (i = 0; i < ele.options.length; i++) {
if (ele.options[i].text == val) {
ele.options[i].selected = true;
}
else {
ele.options[i].selected = false;
}
}
}





DWRUtil.getValue = function(ele, options) {
if (options == null) {
options = {};
}
var orig = ele;
ele = $(ele);


var nodes = document.getElementsByName(orig);
if (ele == null && nodes.length >= 1) {
ele = nodes.item(0);
}
if (ele == null) {
DWRUtil.debug("getValue() can't find an element with id/name: " + orig + ".");
return "";
}

if (DWRUtil._isHTMLElement(ele, "select")) {


var sel = ele.selectedIndex;
if (sel != -1) {
var reply = ele.options[sel].value;
if (reply == null || reply == "") {
reply = ele.options[sel].text;
}

return reply;
}
else {
return "";
}
}

if (DWRUtil._isHTMLElement(ele, "input")) {
if (ele.type == "radio") {
var node;
for (i = 0; i < nodes.length; i++) {
node = nodes.item(i);
if (node.type == "radio") {
if (node.checked) {
if (nodes.length > 1) return node.value;
else return true;
}
}
}
}
switch (ele.type) {
case "checkbox":
case "check-box":
case "radio":
return ele.checked;
default:
return ele.value;
}
}

if (DWRUtil._isHTMLElement(ele, "textarea")) {
return ele.value;
}

if (options.textContent) {
if (ele.textContent) return ele.textContent;
else if (ele.innerText) return ele.innerText;
}
return ele.innerHTML;
};





DWRUtil.getText = function(ele) {
var orig = ele;
ele = $(ele);
if (ele == null) {
DWRUtil.debug("getText() can't find an element with id: " + orig + ".");
return "";
}

if (!DWRUtil._isHTMLElement(ele, "select")) {
DWRUtil.debug("getText() can only be used with select elements. Attempt to use: " + DWRUtil._detailedTypeOf(ele) + " from  id: " + orig + ".");
return "";
}



var sel = ele.selectedIndex;
if (sel != -1) {
return ele.options[sel].text;
}
else {
return "";
}
};





DWRUtil.setValues = function(map) {
for (var property in map) {

if ($(property) != null || document.getElementsByName(property).length >= 1) {
DWRUtil.setValue(property, map[property]);
}
}
};






DWRUtil.getValues = function(data) {
var ele;
if (typeof data == "string") ele = $(data);
if (DWRUtil._isHTMLElement(data)) ele = data;
if (ele != null) {
if (ele.elements == null) {
alert("getValues() requires an object or reference to a form element.");
return null;
}
var reply = {};
var value;
for (var i = 0; i < ele.elements.length; i++) {
if (ele[i].id != null) value = ele[i].id;
else if (ele[i].value != null) value = ele[i].value;
else value = "element" + i;
reply[value] = DWRUtil.getValue(ele[i]);
}
return reply;
}
else {
for (var property in data) {

if ($(property) != null || document.getElementsByName(property).length >= 1) {
data[property] = DWRUtil.getValue(property);
}
}
return data;
}
};





DWRUtil.addOptions = function(ele, data) {
var orig = ele;
ele = $(ele);
if (ele == null) {
DWRUtil.debug("addOptions() can't find an element with id: " + orig + ".");
return;
}
var useOptions = DWRUtil._isHTMLElement(ele, "select");
var useLi = DWRUtil._isHTMLElement(ele, ["ul", "ol"]);
if (!useOptions && !useLi) {
DWRUtil.debug("addOptions() can only be used with select/ul/ol elements. Attempt to use: " + DWRUtil._detailedTypeOf(ele));
return;
}
if (data == null) return;

var text;
var value;
var opt;
var li;
if (DWRUtil._isArray(data)) {

for (var i = 0; i < data.length; i++) {
if (useOptions) {
if (arguments[2] != null) {
if (arguments[3] != null) {
text = DWRUtil._getValueFrom(data[i], arguments[3]);
value = DWRUtil._getValueFrom(data[i], arguments[2]);
}
else {
value = DWRUtil._getValueFrom(data[i], arguments[2]);
text = value;
}
}
else
{
text = DWRUtil._getValueFrom(data[i], arguments[3]);
value = text;
}
if (text || value) {
opt = new Option(text, value);
ele.options[ele.options.length] = opt;
}
}
else {
li = document.createElement("li");
value = DWRUtil._getValueFrom(data[i], arguments[2]);
if (value != null) {
li.innerHTML = value;
ele.appendChild(li);
}
}
}
}
else if (arguments[3] != null) {
for (var prop in data) {
if (!useOptions) {
alert("DWRUtil.addOptions can only create select lists from objects.");
return;
}
value = DWRUtil._getValueFrom(data[prop], arguments[2]);
text = DWRUtil._getValueFrom(data[prop], arguments[3]);
if (text || value) {
opt = new Option(text, value);
ele.options[ele.options.length] = opt;
}
}
}
else {
for (var prop in data) {
if (!useOptions) {
DWRUtil.debug("DWRUtil.addOptions can only create select lists from objects.");
return;
}
if (typeof data[prop] == "function") {

text = null;
value = null;
}
else if (arguments[2]) {
text = prop;
value = data[prop];
}
else {
text = data[prop];
value = prop;
}
if (text || value) {
opt = new Option(text, value);
ele.options[ele.options.length] = opt;
}
}
}
};




DWRUtil._getValueFrom = function(data, method) {
if (method == null) return data;
else if (typeof method == 'function') return method(data);
else return data[method];
}





DWRUtil.removeAllOptions = function(ele) {
var orig = ele;
ele = $(ele);
if (ele == null) {
DWRUtil.debug("removeAllOptions() can't find an element with id: " + orig + ".");
return;
}
var useOptions = DWRUtil._isHTMLElement(ele, "select");
var useLi = DWRUtil._isHTMLElement(ele, ["ul", "ol"]);
if (!useOptions && !useLi) {
DWRUtil.debug("removeAllOptions() can only be used with select, ol and ul elements. Attempt to use: " + DWRUtil._detailedTypeOf(ele));
return;
}
if (useOptions) {
ele.options.length = 0;
}
else {
while (ele.childNodes.length > 0) {
ele.removeChild(ele.firstChild);
}
}
};





DWRUtil.addRows = function(ele, data, cellFuncs, options) {
var orig = ele;
ele = $(ele);
if (ele == null) {
DWRUtil.debug("addRows() can't find an element with id: " + orig + ".");
return;
}
if (!DWRUtil._isHTMLElement(ele, ["table", "tbody", "thead", "tfoot"])) {
DWRUtil.debug("addRows() can only be used with table, tbody, thead and tfoot elements. Attempt to use: " + DWRUtil._detailedTypeOf(ele));
return;
}
if (!options) options = {};
if (!options.rowCreator) options.rowCreator = DWRUtil._defaultRowCreator;
if (!options.cellCreator) options.cellCreator = DWRUtil._defaultCellCreator;
var tr, rowNum;
if (DWRUtil._isArray(data)) {
for (rowNum = 0; rowNum < data.length; rowNum++) {
options.rowData = data[rowNum];
options.rowIndex = rowNum;
options.rowNum = rowNum;
options.data = null;
options.cellNum = -1;
tr = DWRUtil._addRowInner(cellFuncs, options);
if (tr != null) ele.appendChild(tr);
}
}
else if (typeof data == "object") {
rowNum = 0;
for (var rowIndex in data) {
options.rowData = data[rowIndex];
options.rowIndex = rowIndex;
options.rowNum = rowNum;
options.data = null;
options.cellNum = -1;
tr = DWRUtil._addRowInner(cellFuncs, options);
if (tr != null) ele.appendChild(tr);
rowNum++;
}
}
};




DWRUtil._addRowInner = function(cellFuncs, options) {
var tr = options.rowCreator(options);
if (tr == null) return null;
for (var cellNum = 0; cellNum < cellFuncs.length; cellNum++) {
var func = cellFuncs[cellNum];
var td;







var reply = func(options.rowData);
options.data = reply;
options.cellNum = cellNum;
td = options.cellCreator(options);
if (DWRUtil._isHTMLElement(reply, "td")) td = reply;
else if (DWRUtil._isHTMLElement(reply)) td.appendChild(reply);
else td.innerHTML = reply;

tr.appendChild(td);
}
return tr;
};




DWRUtil._defaultRowCreator = function(options) {
return document.createElement("tr");
};




DWRUtil._defaultCellCreator = function(options) {
return document.createElement("td");
};





DWRUtil.removeAllRows = function(ele) {
var orig = ele;
ele = $(ele);
if (ele == null) {
DWRUtil.debug("removeAllRows() can't find an element with id: " + orig + ".");
return;
}
if (!DWRUtil._isHTMLElement(ele, ["table", "tbody", "thead", "tfoot"])) {
DWRUtil.debug("removeAllRows() can only be used with table, tbody, thead and tfoot elements. Attempt to use: " + DWRUtil._detailedTypeOf(ele));
return;
}
while (ele.childNodes.length > 0) {
ele.removeChild(ele.firstChild);
}
};







DWRUtil._isHTMLElement = function(ele, nodeName) {
if (ele == null || typeof ele != "object" || ele.nodeName == null) {
return false;
}

if (nodeName != null) {
var test = ele.nodeName.toLowerCase();

if (typeof nodeName == "string") {
return test == nodeName.toLowerCase();
}

if (DWRUtil._isArray(nodeName)) {
var match = false;
for (var i = 0; i < nodeName.length && !match; i++) {
if (test == nodeName[i].toLowerCase()) {
match =  true;
}
}
return match;
}

DWRUtil.debug("DWRUtil._isHTMLElement was passed test node name that is neither a string or array of strings");
return false;
}

return true;
};




DWRUtil._detailedTypeOf = function(x) {
var reply = typeof x;
if (reply == "object") {
reply = Object.prototype.toString.apply(x);
reply = reply.substring(8, reply.length-1);
}
return reply;
};




DWRUtil._isArray = function(data) {
return (data && data.join) ? true : false;
};




DWRUtil._isDate = function(data) {
return (data && data.toUTCString) ? true : false;
};




DWRUtil._importNode = function(doc, importedNode, deep) {
var newNode;

if (importedNode.nodeType == 1  ) {
newNode = doc.createElement(importedNode.nodeName);

for (var i = 0; i < importedNode.attributes.length; i++) {
var attr = importedNode.attributes[i];
if (attr.nodeValue != null && attr.nodeValue != '') {
newNode.setAttribute(attr.name, attr.nodeValue);
}
}

if (typeof importedNode.style != "undefined") {
newNode.style.cssText = importedNode.style.cssText;
}
}
else if (importedNode.nodeType == 3  ) {
newNode = doc.createTextNode(importedNode.nodeValue);
}

if (deep && importedNode.hasChildNodes()) {
for (i = 0; i < importedNode.childNodes.length; i++) {
newNode.appendChild(DWRUtil._importNode(doc, importedNode.childNodes[i], true));
}
}

return newNode;
}


DWRUtil.debug = function(message) {
alert(message);
}


/*-------- IMPORT FROM ( Name [ dwr/engine.js ], Type [ WebComponetFile  ] ) --------*/
function hashCode(str) {
	var h = 0;
	if (str) {
	    for (var j=str.length-1; j>=0; j--) {
	        h ^= "w5Q2KkFts3deLIPg8Nynu_JAUBZ9YxmH1XW47oDpa6lcjMRfi0CrhbGSOTvqzEV".indexOf(str.charAt(j)) + 1;
	        for (var i=0; i<3; i++) {
	            var m = (h = h<<7 | h>>>25) & 150994944;
	            h ^= m ? (m == 150994944 ? 1 : 0) : 1;
	        }
	    }
	}
	return Math.abs(h);
}

function DWREngine() { }

DWREngine.setErrorHandler = function(handler) {
DWREngine._errorHandler = handler;
};

DWREngine.setWarningHandler = function(handler) {
DWREngine._warningHandler = handler;
};

DWREngine.setTimeout = function(timeout) {
DWREngine._timeout = timeout;
};





DWREngine.setPreHook = function(handler) {
DWREngine._preHook = handler;
};





DWREngine.setPostHook = function(handler) {
DWREngine._postHook = handler;
};


DWREngine.XMLHttpRequest = 1;


DWREngine.IFrame = 2;






DWREngine.setMethod = function(newmethod) {
if (newmethod != DWREngine.XMLHttpRequest && newmethod != DWREngine.IFrame) {
DWREngine._handleError("Remoting method must be one of DWREngine.XMLHttpRequest or DWREngine.IFrame");
return;
}
DWREngine._method = newmethod;
};





DWREngine.setVerb = function(verb) {
if (verb != "GET" && verb != "POST") {
DWREngine._handleError("Remoting verb must be one of GET or POST");
return;
}
DWREngine._verb = verb;
};





DWREngine.setOrdered = function(ordered) {
DWREngine._ordered = ordered;
};





DWREngine.setAsync = function(async) {
DWREngine._async = async;
};





DWREngine.defaultMessageHandler = function(message) {
if (typeof message == "object" && message.name == "Error" && message.description) {
alert("Error: " + message.description);
}
else {
alert(message);
}
};





DWREngine.beginBatch = function() {
if (DWREngine._batch) {
DWREngine._handleError("Batch already started.");
return;
}

DWREngine._batch = {};
DWREngine._batch.map = {};
DWREngine._batch.paramCount = 0;
DWREngine._batch.map.callCount = 0;
DWREngine._batch.ids = [];
DWREngine._batch.preHooks = [];
DWREngine._batch.postHooks = [];
};





DWREngine.endBatch = function(options) {
var batch = DWREngine._batch;
if (batch == null) {
DWREngine._handleError("No batch in progress.");
return;
}

if (options && options.preHook) batch.preHooks.unshift(options.preHook);
if (options && options.postHook) batch.postHooks.push(options.postHook);
if (DWREngine._preHook) batch.preHooks.unshift(DWREngine._preHook);
if (DWREngine._postHook) batch.postHooks.push(DWREngine._postHook);

if (batch.method == null) batch.method = DWREngine._method;
if (batch.verb == null) batch.verb = DWREngine._verb;
if (batch.async == null) batch.async = DWREngine._async;
if (batch.timeout == null) batch.timeout = DWREngine._timeout;

batch.completed = false;


DWREngine._batch = null;



if (!DWREngine._ordered) {
DWREngine._sendData(batch);
DWREngine._batches[DWREngine._batches.length] = batch;
}
else {
if (DWREngine._batches.length == 0) {

DWREngine._sendData(batch);
DWREngine._batches[DWREngine._batches.length] = batch;
}
else {

DWREngine._batchQueue[DWREngine._batchQueue.length] = batch;
}
}
};






DWREngine._errorHandler = DWREngine.defaultMessageHandler;


DWREngine._warningHandler = DWREngine.defaultMessageHandler;


DWREngine._preHook = null;


DWREngine._postHook = null;


DWREngine._batches = [];


DWREngine._batchQueue = [];


DWREngine._handlersMap = {};


DWREngine._method = DWREngine.XMLHttpRequest;


DWREngine._verb = "POST";


DWREngine._ordered = false;


DWREngine._async = true;


DWREngine._batch = null;


DWREngine._timeout = 0;


DWREngine._DOMDocument = ["Msxml2.DOMDocument.5.0", "Msxml2.DOMDocument.4.0", "Msxml2.DOMDocument.3.0", "MSXML2.DOMDocument", "MSXML.DOMDocument", "Microsoft.XMLDOM"];


DWREngine._XMLHTTP = ["Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];










DWREngine._execute = function(path, scriptName, methodName, vararg_params) {
var singleShot = false;
if (DWREngine._batch == null) {
DWREngine.beginBatch();
singleShot = true;
}

var args = [];
for (var i = 0; i < arguments.length - 3; i++) {
args[i] = arguments[i + 3];
}

if (DWREngine._batch.path == null) {
DWREngine._batch.path = path;
}
else {
if (DWREngine._batch.path != path) {
DWREngine._handleError("Can't batch requests to multiple DWR Servlets.");
return;
}
}


var params;
var callData;
var firstArg = args[0];
var lastArg = args[args.length - 1];

if (typeof firstArg == "function") {
callData = { callback:args.shift() };
params = args;
}
else if (typeof lastArg == "function") {
callData = { callback:args.pop() };
params = args;
}
else if (typeof lastArg == "object" && lastArg.callback != null && typeof lastArg.callback == "function") {
callData = args.pop();
params = args;
}
else if (firstArg == null) {



if (lastArg == null && args.length > 2) {
if (DWREngine._warningHandler) {
DWREngine._warningHandler("Ambiguous nulls at start and end of parameter list. Which is the callback function?");
}
}
callData = { callback:args.shift() };
params = args;
}
else if (lastArg == null) {
callData = { callback:args.pop() };
params = args;
}
else {
if (DWREngine._warningHandler) {
DWREngine._warningHandler("Missing callback function or metadata object.");
}
return;
}

/*
var random = Math.floor(Math.random() * 10001);
var id = (random + "_" + new Date().getTime()).toString();
*/

var qry = scriptName+methodName;
for (qryI=0; qryI<params.length; qryI++) qry+=params[qryI];
var id = hashCode(qry);

var prefix = "c" + DWREngine._batch.map.callCount + "-";
DWREngine._batch.ids.push(id);

if (callData.method != null) {
DWREngine._batch.method = callData.method;
delete callData.method;
}
if (callData.verb != null) {
DWREngine._batch.verb = callData.verb;
delete callData.verb;
}
if (callData.async != null) {
DWREngine._batch.async = callData.async;
delete callData.async;
}
if (callData.timeout != null) {
DWREngine._batch.timeout = callData.timeout;
delete callData.timeout;
}


if (callData.preHook != null) {
DWREngine._batch.preHooks.unshift(callData.preHook);
delete callData.preHook;
}
if (callData.postHook != null) {
DWREngine._batch.postHooks.push(callData.postHook);
delete callData.postHook;
}


if (callData.errorHandler == null) callData.errorHandler = DWREngine._errorHandler;
if (callData.warningHandler == null) callData.warningHandler = DWREngine._warningHandler;


DWREngine._handlersMap[id] = callData;

DWREngine._batch.map[prefix + "scriptName"] = scriptName;
DWREngine._batch.map[prefix + "methodName"] = methodName;
DWREngine._batch.map[prefix + "id"] = id;


DWREngine._addSerializeFunctions();
for (i = 0; i < params.length; i++) {
DWREngine._serializeAll(DWREngine._batch, [], params[i], prefix + "param" + i);
}
DWREngine._removeSerializeFunctions();


DWREngine._batch.map.callCount++;
if (singleShot) {
DWREngine.endBatch();
}
};




DWREngine._sendData = function(batch) {

if (batch.map.callCount == 0) return;

for (var i = 0; i < batch.preHooks.length; i++) {
batch.preHooks[i]();
}
batch.preHooks = null;

if (batch.timeout && batch.timeout != 0) {
batch.interval = setInterval(function() {
clearInterval(batch.interval);
DWREngine._abortRequest(batch);
}, batch.timeout);
}

var statsInfo;
if (batch.map.callCount == 1) {
statsInfo = batch.map["c0-scriptName"] + "." + batch.map["c0-methodName"] + ".dwr";
}
else {
statsInfo = "Multiple." + batch.map.callCount + ".dwr";
}


if (batch.method == DWREngine.XMLHttpRequest) {
if (window.XMLHttpRequest) {
batch.req = new XMLHttpRequest();
}

else if (window.ActiveXObject && !(navigator.userAgent.indexOf('Mac') >= 0 && navigator.userAgent.indexOf("MSIE") >= 0)) {
batch.req = DWREngine._newActiveXObject(DWREngine._XMLHTTP);
}
}

var query = "";
var prop;
if (batch.req) {
batch.map.xml = "true";

if (batch.async) {
batch.req.onreadystatechange = function() {
DWREngine._stateChange(batch);
};
}

var indexSafari = navigator.userAgent.indexOf('Safari/');
if (indexSafari >= 0) {

var version = navigator.userAgent.substring(indexSafari + 7);
var verNum = parseInt(version, 10);
if (verNum < 400) {
batch.verb == "GET";
}



}
if (batch.verb == "GET") {



batch.map.callCount = "" + batch.map.callCount;

for (prop in batch.map) {
var qkey = encodeURIComponent(prop);
var qval = encodeURIComponent(batch.map[prop]);
if (qval == "") {
if (DWREngine._warningHandler) {
DWREngine._warningHandler("Found empty qval for qkey=" + qkey);
}
}
query += qkey + "=" + qval + "&";
}
query = query.substring(0, query.length - 1);

try {
batch.req.open("GET", batch.path + "/exec/" + statsInfo + "?" + query, batch.async);
batch.req.send(null);
if (!batch.async) {
DWREngine._stateChange(batch);
}
}
catch (ex) {
DWREngine._handleMetaDataError(null, ex);
}
}
else {
for (prop in batch.map) {
if (typeof batch.map[prop] != "function") {
query += prop + "=" + batch.map[prop] + "\n";
}
}

try {




batch.req.open("POST", batch.path + "/exec/" + statsInfo, batch.async);
batch.req.setRequestHeader('Content-Type', 'text/plain');
batch.req.send(query);
if (!batch.async) {
DWREngine._stateChange(batch);
}
}
catch (ex) {
DWREngine._handleMetaDataError(null, ex);
}
}
}
else {
batch.map.xml = "false";
var idname = "dwr-if-" + batch.map["c0-id"];

batch.div = document.createElement('div');
batch.div.innerHTML = "<iframe frameborder='0' width='0' height='0' id='" + idname + "' name='" + idname + "'></iframe>";
document.body.appendChild(batch.div);
batch.iframe = document.getElementById(idname);
batch.iframe.setAttribute('style', 'width:0px; height:0px; border:0px;');

if (batch.verb == "GET") {
for (prop in batch.map) {
if (typeof batch.map[prop] != "function") {
query += encodeURIComponent(prop) + "=" + encodeURIComponent(batch.map[prop]) + "&";
}
}
query = query.substring(0, query.length - 1);

batch.iframe.setAttribute('src', batch.path + "/exec/" + statsInfo + "?" + query);
document.body.appendChild(batch.iframe);
}
else {
batch.form = document.createElement('form');
batch.form.setAttribute('id', 'dwr-form');
batch.form.setAttribute('action', batch.path + "/exec" + statsInfo);
batch.form.setAttribute('target', idname);
batch.form.target = idname;
batch.form.setAttribute('method', 'post');
for (prop in batch.map) {
var formInput = document.createElement('input');
formInput.setAttribute('type', 'hidden');
formInput.setAttribute('name', prop);
formInput.setAttribute('value', batch.map[prop]);
batch.form.appendChild(formInput);
}

document.body.appendChild(batch.form);
batch.form.submit();
}
}
};




DWREngine._stateChange = function(batch) {
if (!batch.completed && batch.req.readyState == 4) {
try {
var reply = batch.req.responseText;
var status = batch.req.status;

if (reply == null || reply == "") {
DWREngine._handleMetaDataError(null, "No data received from server");
return;
}


if (reply.search("DWREngine._handle") == -1) {
DWREngine._handleMetaDataError(null, "Invalid reply from server");
return;
}

if (status != 200) {
if (reply == null) reply = "Unknown error occured";
DWREngine._handleMetaDataError(null, reply);
return;
}

eval(reply);


DWREngine._clearUp(batch);
}
catch (ex) {
if (ex == null) ex = "Unknown error occured";
DWREngine._handleMetaDataError(null, ex);
}
finally {



if (DWREngine._batchQueue.length != 0) {
var sendbatch = DWREngine._batchQueue.shift();
DWREngine._sendData(sendbatch);
DWREngine._batches[DWREngine._batches.length] = sendbatch;
}
}
}
};






DWREngine._handleResponse = function(id, reply) {

var handlers = DWREngine._handlersMap[id];
DWREngine._handlersMap[id] = null;

if (handlers) {


try {
if (handlers.callback) handlers.callback(reply);
}
catch (ex) {
DWREngine._handleMetaDataError(handlers, ex);
}
}


if (DWREngine._method == DWREngine.IFrame) {
var responseBatch = DWREngine._batches[DWREngine._batches.length-1];

if (responseBatch.map["c"+(responseBatch.map.callCount-1)+"-id"] == id) {
DWREngine._clearUp(responseBatch);
}
}
};




DWREngine._handleServerError = function(id, error) {

var handlers = DWREngine._handlersMap[id];
DWREngine._handlersMap[id] = null;
if (error.message) {
DWREngine._handleMetaDataError(handlers, error.message, error);
}
else {
DWREngine._handleMetaDataError(handlers, error);
}
};




DWREngine._abortRequest = function(batch) {
if (batch && batch.metadata != null && !batch.completed) {
DWREngine._clearUp(batch);
if (batch.req) batch.req.abort();

var handlers;
var id;
for (var i = 0; i < batch.ids.length; i++) {
id = batch.ids[i];
handlers = DWREngine._handlersMap[id];
DWREngine._handleMetaDataError(handlers, "Timeout");
}
}
};




DWREngine._clearUp = function(batch) {
if (batch.completed) {
alert("double complete");
return;
}


if (batch.div) batch.div.parentNode.removeChild(batch.div);
if (batch.iframe) batch.iframe.parentNode.removeChild(batch.iframe);
if (batch.form) batch.form.parentNode.removeChild(batch.form);


if (batch.req) delete batch.req;

for (var i = 0; i < batch.postHooks.length; i++) {
batch.postHooks[i]();
}
batch.postHooks = null;


for (var i = 0; i < DWREngine._batches.length; i++) {
if (DWREngine._batches[i] == batch) {
DWREngine._batches.splice(i, 1);
break;
}
}

batch.completed = true;
};




DWREngine._handleError = function(reason, ex) {
if (DWREngine._errorHandler) {
DWREngine._errorHandler(reason, ex);
}
};




DWREngine._handleMetaDataError = function(handlers, reason, ex) {
if (handlers && typeof handlers.errorHandler == "function") {
handlers.errorHandler(reason, ex);
}
else {
DWREngine._handleError(reason, ex);
}
};




DWREngine._addSerializeFunctions = function() {
Object.prototype.dwrSerialize = DWREngine._serializeObject;
Array.prototype.dwrSerialize = DWREngine._serializeArray;
Boolean.prototype.dwrSerialize = DWREngine._serializeBoolean;
Number.prototype.dwrSerialize = DWREngine._serializeNumber;
String.prototype.dwrSerialize = DWREngine._serializeString;
Date.prototype.dwrSerialize = DWREngine._serializeDate;
};




DWREngine._removeSerializeFunctions = function() {
delete Object.prototype.dwrSerialize;
delete Array.prototype.dwrSerialize;
delete Boolean.prototype.dwrSerialize;
delete Number.prototype.dwrSerialize;
delete String.prototype.dwrSerialize;
delete Date.prototype.dwrSerialize;
};








DWREngine._serializeAll = function(batch, referto, data, name) {
if (data == null) {
batch.map[name] = "null:null";
return;
}

switch (typeof data) {
case "boolean":
batch.map[name] = "boolean:" + data;
break;

case "number":
batch.map[name] = "number:" + data;
break;

case "string":
batch.map[name] = "string:" + encodeURIComponent(data);
break;

case "object":
if (data.dwrSerialize) {
batch.map[name] = data.dwrSerialize(batch, referto, data, name);
}
else if (data.nodeName) {
batch.map[name] = DWREngine._serializeXml(batch, referto, data, name);
}
else {
if (DWREngine._warningHandler) {
DWREngine._warningHandler("Object without dwrSerialize: " + typeof data + ", attempting default converter.");
}
batch.map[name] = "default:" + data;
}
break;

case "function":

break;

default:
if (DWREngine._warningHandler) {
DWREngine._warningHandler("Unexpected type: " + typeof data + ", attempting default converter.");
}
batch.map[name] = "default:" + data;
break;
}
};


DWREngine._lookup = function(referto, data, name) {
var lookup;

for (var i = 0; i < referto.length; i++) {
if (referto[i].data == data) {
lookup = referto[i];
break;
}
}
if (lookup) {
return "reference:" + lookup.name;
}
referto.push({ data:data, name:name });
return null;
};


DWREngine._serializeObject = function(batch, referto, data, name) {
var ref = DWREngine._lookup(referto, this, name);
if (ref) return ref;

if (data.nodeName) {
return DWREngine._serializeXml(batch, referto, data, name);
}


var reply = "Object:{";
var element;
for (element in this)  {
if (element != "dwrSerialize") {
batch.paramCount++;
var childName = "c" + DWREngine._batch.map.callCount + "-e" + batch.paramCount;
DWREngine._serializeAll(batch, referto, this[element], childName);

reply += encodeURIComponent(element);
reply += ":reference:";
reply += childName;
reply += ", ";
}
}

if (reply.substring(reply.length - 2) == ", ") {
reply = reply.substring(0, reply.length - 2);
}
reply += "}";

return reply;
};


DWREngine._serializeXml = function(batch, referto, data, name) {
var ref = DWREngine._lookup(referto, this, name);
if (ref) {
return ref;
}
var output;
if (window.XMLSerializer) {
var serializer = new XMLSerializer();
output = serializer.serializeToString(data);
}
else {
output = data.toXml;
}
return "XML:" + encodeURIComponent(output);
};


DWREngine._serializeArray = function(batch, referto, data, name) {
var ref = DWREngine._lookup(referto, this, name);
if (ref) return ref;

var reply = "Array:[";
for (var i = 0; i < this.length; i++) {
if (i != 0) {
reply += ",";
}

batch.paramCount++;
var childName = "c" + DWREngine._batch.map.callCount + "-e" + batch.paramCount;
DWREngine._serializeAll(batch, referto, this[i], childName);
reply += "reference:";
reply += childName;
}
reply += "]";

return reply;
};


DWREngine._serializeBoolean = function(batch, referto, data, name) {
return "Boolean:" + this;
};


DWREngine._serializeNumber = function(batch, referto, data, name) {
return "Number:" + this;
};


DWREngine._serializeString = function(batch, referto, data, name) {
return "String:" + encodeURIComponent(this);
};


DWREngine._serializeDate = function(batch, referto, data, name) {
return "Date:" + this.getTime();
};


DWREngine._unserializeDocument = function(xml) {
var dom;
if (window.DOMParser) {
var parser = new DOMParser();
dom = parser.parseFromString(xml, "text/xml");
if (!dom.documentElement || dom.documentElement.tagName == "parsererror") {
var message = dom.documentElement.firstChild.data;
message += "\n" + dom.documentElement.firstChild.nextSibling.firstChild.data;
throw message;
}
return dom;
}
else if (window.ActiveXObject) {
dom = DWREngine._newActiveXObject(DWREngine._DOMDocument);
dom.loadXML(xml);

return dom;
}








else {
var div = document.createElement('div');
div.innerHTML = xml;
return div;
}
};





DWREngine._newActiveXObject = function(axarray) {
var returnValue;
for (var i = 0; i < axarray.length; i++) {
try {
returnValue = new ActiveXObject(axarray[i]);
break;
}
catch (ex) {
}
}
return returnValue;
};


if (typeof window.encodeURIComponent === 'undefined') {
DWREngine._utf8 = function(wide) {
wide = "" + wide;
var c;
var s;
var enc = "";
var i = 0;
while (i < wide.length) {
c = wide.charCodeAt(i++);

if (c >= 0xDC00 && c < 0xE000) continue;
if (c >= 0xD800 && c < 0xDC00) {
if (i >= wide.length) continue;
s = wide.charCodeAt(i++);
if (s < 0xDC00 || c >= 0xDE00) continue;
c = ((c - 0xD800) << 10) + (s - 0xDC00) + 0x10000;
}

if (c < 0x80) {
enc += String.fromCharCode(c);
}
else if (c < 0x800) {
enc += String.fromCharCode(0xC0 + (c >> 6), 0x80 + (c & 0x3F));
}
else if (c < 0x10000) {
enc += String.fromCharCode(0xE0 + (c >> 12), 0x80 + (c >> 6 & 0x3F), 0x80 + (c & 0x3F));
}
else {
enc += String.fromCharCode(0xF0 + (c >> 18), 0x80 + (c >> 12 & 0x3F), 0x80 + (c >> 6 & 0x3F), 0x80 + (c & 0x3F));
}
}
return enc;
}

DWREngine._hexchars = "0123456789ABCDEF";

DWREngine._toHex = function(n) {
return DWREngine._hexchars.charAt(n >> 4) + DWREngine._hexchars.charAt(n & 0xF);
}

DWREngine._okURIchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";

window.encodeURIComponent = function(s)  {
s = DWREngine._utf8(s);
var c;
var enc = "";
for (var i= 0; i<s.length; i++) {
if (DWREngine._okURIchars.indexOf(s.charAt(i)) == -1) {
enc += "%" + DWREngine._toHex(s.charCodeAt(i));
}
else {
enc += s.charAt(i);
}
}
return enc;
}
}


if (typeof Array.prototype.splice === 'undefined') {
Array.prototype.splice = function(ind, cnt)
{
if (arguments.length == 0) {
return ind;
}
if (typeof ind != "number") {
ind = 0;
}
if (ind < 0) {
ind = Math.max(0,this.length + ind);
}
if (ind > this.length) {
if (arguments.length > 2) {
ind = this.length;
}
else {
return [];
}
}
if (arguments.length < 2) {
cnt = this.length-ind;
}

cnt = (typeof cnt == "number") ? Math.max(0, cnt) : 0;
removeArray = this.slice(ind, ind + cnt);
endArray = this.slice(ind + cnt);
this.length = ind;

for (var i = 2; i < arguments.length; i++) {
this[this.length] = arguments[i];
}
for (i = 0; i < endArray.length; i++) {
this[this.length] = endArray[i];
}

return removeArray;
}
}


if (typeof Array.prototype.shift === 'undefined') {
Array.prototype.shift = function(str) {
var val = this[0];
for (var i = 1; i < this.length; ++i) {
this[i - 1] = this[i];
}
this.length--;
return val;
}
}


if (typeof Array.prototype.unshift === 'undefined') {
Array.prototype.unshift = function() {
var i = unshift.arguments.length;
for (var j = this.length - 1; j >= 0; --j) {
this[j + i] = this[j];
}
for (j = 0; j < i; ++j) {
this[j] = unshift.arguments[j];
}
}
}


if (typeof Array.prototype.push === 'undefined') {
Array.prototype.push = function() {
var sub = this.length;
for (var i = 0; i < push.arguments.length; ++i) {
this[sub] = push.arguments[i];
sub++;
}
}
}


if (typeof Array.prototype.pop === 'undefined') {
Array.prototype.pop = function() {
var lastElement = this[this.length - 1];
this.length--;
return lastElement;
}
}


/*-------- IMPORT FROM ( Name [ SSH_PDP_SCRIPT3 ], Type [ H ], Class [ WebComponetVo ] ) --------*/
function mli(){

	wOpen("http://www.mercadolibre.com.ar/argentina/ml/p_html?as_html_id=POP_UPMERCADOLIDER", "", 400, 400, "no", "");

}

function mligold(){

	wOpen("http://www.mercadolibre.com.ar/argentina/ml/p_html?as_html_id=POP_UPMERCADOLIDERG", "", 400, 400, "no", "");

}

function mliplat(){

	wOpen("http://www.mercadolibre.com.ar/argentina/ml/p_html?as_html_id=POP_UPMERCADOLIDERP", "", 400, 400, "no", "");

}
var actionForm = 'http://opinion.mercadolibre.com.mx/jm/catalogPdpImageLoader';
var actionFormMan = 'http://opinion.mercadolibre.com.mx/jm/catalogPdpMediaLoader';
var gDivID = 'divReg';
var lblLogout = 'Salir';
var oldPathPdp = "http://www.mercadolibre.com.mx/jm/search";
ReviewsDwr._path = 'http://'+window.location.host+ReviewsDwr._path;
var queryString = oldUrl.substr(oldUrl.indexOf("?"));
var oldPath = oldUrl.substr(0,oldUrl.indexOf("?"));
/* --------- Gen:31 --------- */

