function LocationLoader() { this.lastLocationArea = null; this.states = null; this.cities = null; this.parentCityObj = null; this.currentGuideId = null; // dados iniciais this.defaultCityId = null; this.defaultStateId = null; this.defaultZoneId = null; this.cityDropDown = null; this.lastWrittenStateDesc = null; this.lastWrittenCityDesc = null; this.selectedStateDesc = ""; this.selectedCityDesc = ""; this.selectedStateId = ""; this.selectedCityId = ""; this.searchInputSearch = null; // Objs de imagem this.stateCityArrow = null; this.stateArrow = null; this.cityArrow = null; // Objs loading animation this.divStateCityLoading = null; // Objs onde são escritos as descrições this.stateCityValueDiv = null; this.stateValueDiv = null; this.cityValueDiv = null; this.m_areaTop = '19px'; this.m_areaLeft = '-107px'; this.m_areaWidth = '203px'; this.m_areaHeight = '85px'; this.m_stateWidth = 57; this.m_stateHeight = 80; if(document.all) { this.m_stateOffsetTop = 12; } else { this.m_stateOffsetTop = 18; } this.m_stateOffsetLeft = 1; this.m_cityWidth = 120; this.m_cityHeight = 80; this.m_cityOffsetTop = 18; this.m_cityOffsetLeft = -1; this.oldBodyClick = null; this.isFocused = true; function openLocationArea(pCurrentGuideId, content, parentObj, pSearchInputField) { this.currentGuideId = pCurrentGuideId; this.searchInputSearch = pSearchInputField; if(this.lastLocationArea != null) { this.destroyLocationArea(); } else { var cityDropDownArea = new DropDownArea("cityDropDownArea"); cityDropDownArea.top = this.m_areaTop; cityDropDownArea.left = this.m_areaLeft; cityDropDownArea.width = this.m_areaWidth; cityDropDownArea.height = this.m_areaHeight; cityDropDownArea.zIndex = 1000; //cityDropDownArea.position = 'relative'; cityDropDownArea.backImage = "img/bg_location.gif"; cityDropDownArea.parentDiv = parentObj; cityDropDownArea.draw(locationsHtml); this.lastLocationArea = cityDropDownArea; this.initialize(); this.stopLoadingAnimation(); } } this.openLocationArea = openLocationArea; function initialize() { // guardando referencia as setas dos dropdowns this.stateCityArrow = document.getElementById("divStateCityComboRight"); this.stateArrow = document.getElementById("divStateComboArrow"); this.cityArrow = document.getElementById("divCityComboArrow"); this.stateCityValueDiv = document.getElementById("divStateCityComboValue"); this.stateValueDiv = document.getElementById("divStateValue"); this.cityValueDiv = document.getElementById("divCityValue"); this.divStateCityLoading = document.getElementById("divStateCityLoading"); this.setAreaArrowUp(this.stateCityArrow); this.createDropDownAreaEvent(); if(this.lastWrittenStateDesc != null) { this.writeStateDesc(this.lastWrittenStateDesc); } else { this.selectedStateId = this.defaultStateId; } if(this.lastWrittenCityDesc != null) { this.writeCityDesc(this.lastWrittenCityDesc); } else { this.selectedCityId = this.defaultCityId; } if(this.lastWrittenZoneDesc != null) { this.writeZoneDesc(this.lastWrittenZoneDesc); } else { this.selectedZoneId = this.defaultZoneId; } } this.initialize = initialize; function createDropDownAreaEvent() { if(document.body.onclick != null) { document.body.onclick(); } this.oldBodyClick = document.body.onclick; var _this = this; var delayedSetEvent = function() { document.body.onclick = function() { if(_this.oldBodyClick != null) { _this.oldBodyClick(); } _this.onLostFocus(_this); }; }; setTimeout(delayedSetEvent, 20); this.lastLocationArea.dropdownAreaDiv.onmousedown = function() { _this.isFocused = true; }; this.isFocused = false; } this.createDropDownAreaEvent = createDropDownAreaEvent; function recoverDropDownAreaEvent() { document.body.onclick = this.oldBodyClick; this.oldBodyClick = null; } this.recoverDropDownAreaEvent = recoverDropDownAreaEvent; function onLostFocus(pObjRef) { if( pObjRef.isFocused == false ) { pObjRef.closeLocationArea(); } pObjRef.isFocused = false; } this.onLostFocus = onLostFocus; function setAreaArrowDown(pImgObj) { pImgObj.style.backgroundImage = 'url(img/cb_arrow_down.gif)'; } this.setAreaArrowDown = setAreaArrowDown; function setAreaArrowUp(pImgObj) { pImgObj.style.backgroundImage = 'url(img/cb_arrow_up.gif)'; } this.setAreaArrowUp = setAreaArrowUp; function setDropDownArrowDown(pImgObj) { pImgObj.style.backgroundImage = 'url(img/arrow_down_gray.gif)'; } this.setDropDownArrowDown = setDropDownArrowDown; function setDropDownArrowUp(pImgObj) { pImgObj.style.backgroundImage = 'url(img/arrow_up_gray.gif)'; } this.setDropDownArrowUp = setDropDownArrowUp; function onClickOK() { window.localeMarketId = this.selectedStateId; window.localeCityId = this.selectedCityId; this.writeStateCityValue(); this.closeLocationArea(); var newUrl = "home.do?method=showHome&guideId=" + this.currentGuideId + "&localeMarketId=" + this.selectedStateId; if(this.selectedCityId != null && this.selectedCityId != "") { newUrl += "&localeCityId=" + this.selectedCityId; } if(this.searchInputSearch != null && this.searchInputSearch.value != "") { newUrl += "&keywordComplet=" + this.searchInputSearch.value; } window.location = newUrl; } this.onClickOK = onClickOK; function closeLocationArea() { if(this.lastLocationArea != null) { this.destroyLocationArea(); } } this.closeLocationArea = closeLocationArea; function writeStateCityValue() { var value = ""; var stateValue = Trim(this.stateValueDiv.innerHTML); value += stateValue; var cityValue = Trim(this.cityValueDiv.innerHTML); if(cityValue != null && cityValue != "Ciudad") { value += " - " + cityValue; } this.stateCityValueDiv.innerHTML = value; this.lastWrittenStateDesc = stateValue; this.lastWrittenCityDesc = cityValue; } this.writeStateCityValue = writeStateCityValue; function writeStateDesc(pDesc) { this.stateValueDiv.innerHTML = Trim(pDesc); } this.writeStateDesc = writeStateDesc; function writeCityDesc(pDesc) { this.cityValueDiv.innerHTML = Trim(pDesc); } this.writeCityDesc = writeCityDesc; function selectUf(pId, pDesc) { this.selectedStateDesc = pDesc; this.selectedStateId = pId; this.destroyStateDropDown(); this.loadCities(pId); this.writeStateDesc(this.selectedStateDesc); this.selectCity(null, "Ciudad"); } this.selectUf = selectUf; function selectCity(pId, pDesc) { this.selectedCityDesc = pDesc; this.selectedCityId = pId; this.writeCityDesc(this.selectedCityDesc); this.destroyCityDropDown(); } this.selectCity = selectCity; function contains(pFrame, pObject) { do { pObject = pObject.offsetParent; if(pObject == pFrame) { return true; } } while(pObject.tagName!="BODY"); } this.contains = contains; this.stateDropDown = null; function showStateDropDown(parentDiv) { this.destroyCityDropDown(); this.destroyZoneDropDown(); if(this.stateDropDown != null) { this.destroyStateDropDown(); } else { this.drawStateDropDown(parentDiv); this.setDropDownArrowUp(this.stateArrow); var _this = this; document.getElementById("divStateDropDown").onmousedown = function() { _this.isFocused = true; }; } } this.showStateDropDown = showStateDropDown; function drawStateDropDown(parentDiv) { this.stateDropDown = new DropDownMenu("divStateDropDown"); for(var i = 0; i < this.states.length; i++) { this.stateDropDown.addDropDownMenuItem(states[i]); } this.stateDropDown.width = this.m_stateWidth; this.stateDropDown.height = this.m_stateHeight; this.stateDropDown.top = findPosY(document.getElementById("divStateCombo")) + this.m_stateOffsetTop; this.stateDropDown.left = findPosX(document.getElementById("divStateCombo")) + this.m_stateOffsetLeft; this.stateDropDown.backImage = null; this.stateDropDown.zIndex = 1100; this.stateDropDown.draw(parentDiv); } this.drawStateDropDown = drawStateDropDown; function showCityDropDown(parentDiv) { this.destroyStateDropDown(); this.destroyZoneDropDown(); if(this.cityDropDown != null) { this.destroyCityDropDown(); } else { this.parentCityObj = parentDiv; this.drawCityDropDown(parentDiv); this.setDropDownArrowUp(this.cityArrow); var _this = this; document.getElementById("divCityDropDown").onmousedown = function() { _this.isFocused = true; }; } } this.showCityDropDown = showCityDropDown; function drawCityDropDown(parentDiv) { this.cityDropDown = new DropDownMenu("divCityDropDown"); for(var i = 0; i < this.cities.length; i++) { this.cityDropDown.addDropDownMenuItem(this.cities[i]); } this.cityDropDown.width = this.m_cityWidth; this.cityDropDown.height = this.m_cityHeight; this.cityDropDown.top = findPosY(document.getElementById("divCityValue")) + this.m_cityOffsetTop; this.cityDropDown.left = findPosX(document.getElementById("divCityValue")) + this.m_cityOffsetLeft; this.cityDropDown.backImage = null; this.cityDropDown.zIndex = 1100; this.parentCityObj = document.getElementById('divStateCity'); this.cityDropDown.draw(this.parentCityObj); } this.drawCityDropDown = drawCityDropDown; function loadCities(pMarketId) { this.startLoadingAnimation(); var xmlHttpWrapper = new XMLHTTPWrapper(); xmlHttpWrapper.callURL("location.do?method=loadCity&localeMarketId="+ pMarketId, this.onLoadCitiesComplete, this); } this.loadCities = loadCities; function onLoadCitiesComplete(citiesText, pThis) { pThis.cities = new Array(); pThis.cities.push(new DropDownMenuItem("locationLoader.selectCity(\"\", \"Ciudad\"); locationLoader.destroyCityStateDropDown(); ", "Todas", "Todas")); if(citiesText != null && citiesText != "") { var splitCities = citiesText.split("|"); for(var i = 0; i < splitCities.length; i++) { var city = splitCities[i].split(","); pThis.cities.push(new DropDownMenuItem("locationLoader.selectCity(\""+ city[0] +"\", \""+ city[1] +"\"); locationLoader.destroyCityStateDropDown(); ", city[1], "")); } } pThis.stopLoadingAnimation(); } this.onLoadCitiesComplete = onLoadCitiesComplete; function destroyLocationArea() { if (this.lastLocationArea != null ) { this.lastLocationArea.destroy(); this.lastLocationArea = null; this.recoverDropDownAreaEvent(); this.destroyCityStateDropDown(); this.stopLoadingAnimation(); } } this.destroyLocationArea = destroyLocationArea; function destroyStateDropDown() { if (this.stateDropDown != null ) { this.stateDropDown.destroy(); this.stateDropDown = null; this.setDropDownArrowDown(this.stateArrow); } } this.destroyStateDropDown = destroyStateDropDown; function destroyCityDropDown() { if (this.cityDropDown != null ) { this.cityDropDown.destroy(); this.cityDropDown = null; this.setDropDownArrowDown(this.cityArrow); } } this.destroyCityDropDown = destroyCityDropDown; // implementar na classe filha function destroyZoneDropDown() { } this.destroyZoneDropDown = destroyZoneDropDown; function destroyCityStateDropDown() { this.destroyStateDropDown(); this.destroyCityDropDown(); } this.destroyCityStateDropDown = destroyCityStateDropDown function stopLoadingAnimation() { this.divStateCityLoading.style.display = 'none'; } this.stopLoadingAnimation = stopLoadingAnimation; function startLoadingAnimation() { this.divStateCityLoading.style.display = 'block'; } this.startLoadingAnimation = startLoadingAnimation; function setStates(pStates) { this.states = pStates; } this.setStates = setStates; function setCities(pCities) { this.cities = pCities; } this.setCities = setCities; function setZones(pZones) { this.zones = pZones; } this.setZones = setZones; function setDefaultState(id, name) { this.defaultStateId = id; } this.setDefaultState = setDefaultState; function setDefaultCity(id, name) { this.defaultCityId = id; } this.setDefaultCity = setDefaultCity; function setDefaultZone(id, name) { this.defaultZoneId = id; } this.setDefaultZone = setDefaultZone; }