// --- [start /site/entertainmentSearch.js] ---
/* ****************** */
// Initialise calendar
var endDate = new Date();
endDate.setTime(endDate.getTime()+(1000*60*60*24*30*11));
var month = endDate.getMonth();
if (month == 0) month = 12;
endDate = endDate.getDate()+'/'+month+'/'+endDate.getFullYear()
var category='frontier';
startUpCalendar(theDate,endDate,'entsSearchForm','dayVal','monthVal');
		
/* ************************* */
// Form default field checking

function formCleanup() {
	var searchFields = lm.e('ents_search').getElementsByTagName('input');
	
	for (var i = 0, j = searchFields.length; i < j; i++) {	
		if ((searchFields[i].getAttribute('type') == 'text') && (searchFields[i].value == defaultText)) {
			searchFields[i].onfocus = function() { if (this.value == defaultText) { this.value = '';	}}
			searchFields[i].onblur  = function() { if (this.value == '') { this.value = defaultText;	}}
		}
	}
}

/* ************************* */
// Form field remove accents - list the elements that need to be stripped

lm.addEvent({e:lm.e('ents_search'), eT:'submit', fn:function(){
		lm.e('eventName').value=stripVowelAccent(lm.e('eventName').value,"");
		lm.e('eventLocation').value=stripVowelAccent(lm.e('eventLocation').value,"");
	}
})


/* *********************** */
// Hide show toggle

var advShowSearchText = 'View advanced options: Search price, category, no. of tickets';
var advHideSearchText = 'Hide advanced search';
		
function toggle(toggler,obj) {	
	var toggler = lm.e(toggler);
	var el = lm.e(obj);	
	el.style.display = (el.style.display != 'none') ? 'none' : 'block';
	toggler.innerHTML = (toggler.innerHTML != advShowSearchText) ? advShowSearchText : advHideSearchText;
}

var togglers = {
	init : function() {
		if(lm.e('advSearchBox')) {
			lm.e('advSearchBox').style.display = (lm.querystring.numTickets || lm.querystring.maxPrice || lm.querystring.catID) ? 'block' : 'none';
			lm.e('advSearchToggle').innerHTML = (lm.querystring.numTickets || lm.querystring.maxPrice || lm.querystring.catID) ? advHideSearchText : advShowSearchText;
			lm.addEvent({e:lm.e('advSearchToggle'), eT:'click', fn:function() { 
				toggle('advSearchToggle','advSearchBox'); } 
			});
		}
	}
}

// ***********************************
//Event Registration - uses LM library

if(typeof lm == 'object'){
	lm.addEvent({fn:formCleanup});	
/*	lm.addEvent({fn:function(){ 
		togglers.init();
	}})*/
	
}	

/* *********************** */
// Category list dropdown build

if (lm.e('eventCatId')) {						//Check for existence of category dropdown
	var eventTypes = function(){
		var _this = { 
			//get the references of the first select containing the list of Event type
			eventType:lm.e('entType'),
			
			//get the reference of the second select containing the event type category
			eventCatList:lm.e('eventCatId'),	
			 
			//declare an array that contain the event type object
			eventTypeList:[],
			// Event Type object constructor function
			EventType:function(name, value, index){ 
				// the name of the event type 
				this.name = name;
				// the value of the event type luckily for us this is a number 
				this.value = value;
				this.index = index;
				this.Options = [];
				var optGroupOptions = _this.eventCatList.getElementsByTagName('optgroup')[this.index].getElementsByTagName('option')
				for(var i=0, j=optGroupOptions.length; i < j; i++){
					this.Options.push(new Option(optGroupOptions[i].text, optGroupOptions[i].value, false, (optGroupOptions[i].value==lm.querystring.catID)?true:false));
				}
				this.populateCatList = function(){
					_this.eventCatList.disabled = false; 
					while(_this.eventCatList.getElementsByTagName('optgroup').length > 0) {
						_this.eventCatList.removeChild(_this.eventCatList.getElementsByTagName('optgroup')[0])
					}
					while(_this.eventCatList.options.length > 0){
						_this.eventCatList.options[_this.eventCatList.options.length-1] = null
					}
					for(var i=0, j=this.Options.length; i < j; i++) {
						
						_this.eventCatList.options[i] = this.Options[i];
					}
				}
			},
			getEventTypes:function(){
				for(var i=0, j=this.eventType.options.length; i < j; i++){
					if(this.eventType.options[i].value!=''){
						this.eventTypeList.push(new this.EventType(this.eventType.options[i].text, this.eventType.options[i].value, i-1)) 
					}
				}
			},
			showCategory:function(obj){ 
				if(obj.value!=''){
					this.eventTypeList[obj.selectedIndex-1].populateCatList()
				}
				else{
					while(_this.eventCatList.getElementsByTagName('optgroup').length > 0) {
						_this.eventCatList.removeChild(_this.eventCatList.getElementsByTagName('optgroup')[0])
					}
					while(_this.eventCatList.options.length > 0){
						_this.eventCatList.options[_this.eventCatList.options.length-1] = null
					}
					_this.eventCatList.style.visibility = 'hidden';
					for(i=0;i< this.eventTypeList.length;i++)
					{
						var optGroup = document.createElement('OPTGROUP');
						optGroup.label = this.eventTypeList[i].name;
						optGroup.id = this.eventTypeList[i].value+'-optgroup';
						optionsInGroup = this.eventTypeList[i].Options.length - 1;
						for(var k=0; k < optionsInGroup; k++) {			
							option=document.createElement("option");
							optionText=document.createTextNode(this.eventTypeList[i].Options[k].text);
							option.appendChild(optionText);
							option.setAttribute("value",this.eventTypeList[i].Options[k].value);						
							optGroup.appendChild(option);
						}
						_this.eventCatList.appendChild(optGroup)
					}
					_this.eventCatList.style.visibility='inherit';
				}
			},
			clearEventCatList:function(){
				/*while(this.eventCatList.options.length > 0) {
					this.eventCatList.options[this.eventCatList.options.length-1] = null
				}*/
				for(i=0; i < this.eventCatList.options.length; i++ ){
					this.eventCatList.options[i] = null
				}
				this.showCategory(this.eventType)

			}
		}
		_this.getEventTypes(_this.eventCatList);
	
		_this.clearEventCatList();	
		return _this;
	}()
}

/* recently search */
var cookieFormName='ents_search';	
if(typeof lm == 'object' && typeof lm.form == 'object'){
	var formUtility = new lm.form.utility(cookieFormName);
	
	formUtility.remember = {
		p:['keyword', 'location', 'eventType', 'searchRadius', 'dateAllowance', 'numTickets', 'maxPrice','catID'],
		s:['dayVal', 'monthVal']
	};
	
	formUtility.recentlySearch = true;
}
// --- [end prdpcthpb0201:4003 - /site/entertainmentSearch.js - Feb 9, 2010 12:46 pm GMT - akamai,pcth0406,pct0410 - TweT1QqoQroAABv-s9AAACBq - cache 1800 ] ---
