/* Dependencies: Mootools Core 1.2.4+ - * (recheck before optimizing) */ /* * PagingBox: convenience Class to reorganize hyperlinks * SearchSelection : convenience Class to set and check input fields * @author cbo@comspace.de */ var PagingBox = new Class({ Implements: Options, options: { pagingRange : 5, pagingElements : 'div.paging a' }, initialize : function(options){ this.setOptions(options); this.getHyperLinks(); }, getHyperLinks : function(ev){ var aArray = $$(this.options.pagingElements); var defRange = this.options.pagingRange; var page = parseInt($('getPageId').get('html')); if(page > aArray.length || page < 1){ page = 1; } aArray.each(function(element, i){ element.set('href',element.get('href') + '#result') if((i+1) === page){ element.addClass('active'); this.setPaging((i+1)); } }.bind(this)); }, setPaging : function(pos){ var aArray = $$(this.options.pagingElements); var start = pos - this.options.pagingRange; if(pos < 2){ start = 1; } var firstLink = new Element('a', { 'href': aArray[0].get('href'), 'style' : 'margin-right: 3px', 'html': '<<' }); $('setPreAnc').grab(firstLink); var end = pos + this.options.pagingRange; if(pos > aArray.length-1){ end = aArray.length; } var lastLink = new Element('a', { 'href': aArray.getLast().get('href'), 'html': '>>' }); $$('div.paging').grab(lastLink); aArray.each(function(element, i){ if((i+1) > end || (i+1) < start){ if((i+1) > start && (i+1) < end){ element.setStyle('display',''); }else{ element.setStyle('display','none'); } }else{ element.setStyle('display',''); } }); } }); var SearchSelection = new Class({ Implements: Options, options: { country : '', province : '', product : '', custom : '', searchByName : '' }, initialize : function(options){ this.setOptions(options); this.setSearchSelection(); this.createEventSearchByName(); this.exceptionHandler(); }, setSearchSelection : function(){ var setOption = $$('div.form-wrapper option'); setOption.each(function(option){ option.set('value',option.get('value').clean()); option.set('html',option.get('html').clean()); if((option.get('value')) === this.options.country || option.get('value') === this.options.product || option.get('value') === this.options.province){ option.set('selected','selected'); } }.bind(this)); if(this.options.custom === ''){ $('partner-name').set('value',this.options.searchByName); }else{ $('partner-name').set('value',this.options.custom); } }, createEventSearchByName : function(){ var searchField = $('partner-name'); $('partner-reset').addEvent('click',function(ev){ ev.stop(); $('partner-country').getFirst('option').set('selected','selected'); $('partner-province').getFirst('option').set('selected','selected'); $('partner-product').getFirst('option').set('selected','selected'); searchField.set('value', ''); }); $$('a.iframehref').addEvent('click',function(event){ event.stop(); var aHref = event.target.get('href').clean(); var splitHref= aHref.split('='); var myMap = splitHref[0]+'='+encodeURI(splitHref[1]); SexyLightbox.display(myMap+'&controlFlag=1&TB_iframe=1&width=700&height=400', '', 'iframe'); }); }, exceptionHandler : function(){ var resultBox = $('pl-result-box'); resultBox.setStyle('display','none'); $$('div.paging').setStyle('display','none'); var queryString = window.location.search; var arr1 = new Array(); arr1 = queryString.split('&'); var isAutosubmit = false; for (var i = 0; i < arr1.length; i++){ if (arr1[i].toString() === 'autosubmit=1'){ isAutosubmit = true; } } if($$('div.expandable-item').length > 0 && isAutosubmit == false){ $('partner-default').setStyle('display','none'); resultBox.setStyle('display',''); $$('div.paging').setStyle('display',''); } else { var exceptionFlag = 0; var fieldArray = $('partner-default').getElements('p'); if (isAutosubmit == false){ if(this.options.country != '' && this.options.custom != ''){ fieldArray.setStyle('display','none'); fieldArray[1].setStyle('display',''); resultBox.setStyle('display',''); } else if(this.options.country != '' || this.options.custom != ''){ fieldArray.setStyle('display','none'); fieldArray[0].setStyle('display',''); resultBox.setStyle('display',''); } } } }});