// (c)2011 MrOrange

﻿
mrO.searchInput=function(id,className,args){mrO.object.call(this,id,className,args);var defaultSettings={sourceType:"air"};this.applyDefaultSettings(defaultSettings);this.elementInputs={};this.cityInputs={};this.dateInputs={};};mrO.searchInput.prototype=new mrO.object;mrO.searchInput.prototype.init=function(){};mrO.searchInput.prototype.getRequestParametersString=function(){var params=this.getParametersObject();return mrO.utils.getRequestParametersString(params);};mrO.searchInput.prototype.valid=function(){var error="";if(error!==""){alert(error);return false;}
return true;};mrO.searchInput.prototype.getParametersObject=function(){var parameterArray={};var utilLib=mrO.utils;parameterArray["city1"]=utilLib.URLEncodeString(this.getCity1IATA());parameterArray["city2"]=utilLib.URLEncodeString(this.getCity2IATA());parameterArray["city3"]=utilLib.URLEncodeString(this.getCity3IATA());parameterArray["city4"]=utilLib.URLEncodeString(this.getCity4IATA());parameterArray["date1"]=utilLib.URLEncodeString(this.getDate1());parameterArray["date2"]=utilLib.URLEncodeString(this.getDate2());var debugging=mrO.page.debugging({sender:'getParametersObject'});var notAdded="NOT ADDING!\n\n";for(var element in this.elementInputs){var value=this.elementInputs[element].getValue();if(typeof(value)!=='undefined'&&value!==null&&value!==""){if(utilLib.isElementActive(this.elementInputs[element].element)){parameterArray[this.elementInputs[element].significance]=utilLib.URLEncodeString(this.elementInputs[element].getValue());}else if(this.elementInputs[element].template==="RadioButtonGroup"){parameterArray[this.elementInputs[element].significance]=utilLib.URLEncodeString(this.elementInputs[element].getValue());}else if(debugging===true){notAdded=notAdded+this.elementInputs[element].significance+'\n'+this.elementInputs[element].id+'\n\thidden? '+$(this.elementInputs[element].element).is(':hidden')+'\n\tvisible? '+$(this.elementInputs[element].element).is(':visible')+'\n\n';}}}
if(debugging===true){mrO.utils.writeToConsole(notAdded)};return parameterArray;};mrO.searchInput.prototype.sing=function(){var singString="";singString=singString+this.getCity1IATA()+"\n";singString=singString+this.getCity2IATA()+"\n";singString=singString+this.getDate1()+"\n";singString=singString+this.getDate2()+"\n";for(var element in this.elementInputs){singString=singString+this.elementInputs[element].significance+": \t"+this.elementInputs[element].getValue()+"\n";}
return singString;};mrO.searchInput.elementObject=function(significance,id,template){this.significance=significance;this.id=id;this.template=template;this.element=null;};mrO.searchInput.elementObject.prototype.ensureElements=function(){if(this.element===null&&this.id!==null){this.element=document.getElementById(this.id);}};mrO.searchInput.elementObject.prototype.sing=function(){return"significance: "+this.significance+" \tid: "+this.id+" \ttemplate: "+this.template;};mrO.searchInput.elementObject.prototype.getValue=function(){this.ensureElements();if(this.template==="TextBox"){return this.element.value;}else if(this.template==="DropDown"){return this.element[this.element.selectedIndex].value;}else if(this.template==="CheckBox"){if(typeof(this.checkbox_on_selected_value)==='undefined'&&typeof(this.checkbox_on_unselected_value)==='undefined'){return(this.element.checked?"1":"0");}else{return(this.element.checked?this.checkbox_on_selected_value:this.checkbox_on_unselected_value);}}else if(this.template==="InvertedCheckBox"){if(typeof(this.checkbox_on_selected_value)==='undefined'&&typeof(this.checkbox_on_unselected_value)==='undefined'){return(this.element.checked?"0":"1");}else{return(this.element.checked?this.checkbox_on_unselected_value:this.checkbox_on_selected_value);}}else if(this.template==="RadioButtonGroup"){return $("input:radio[name="+this.id+"]:checked").val();}else{return"can't match template: "+this.template;}};mrO.searchInput.dateInputObject=function(significance,textboxId,dateDropdownId,monthDropdownId){this.significance=significance;this.textboxId=textboxId;this.dateDropdownId=dateDropdownId;this.monthDropdownId=monthDropdownId;this.textboxElement=null;this.dateDropdownElement=null;this.monthDropdownElement=null;};mrO.searchInput.dateInputObject.prototype.ensureElements=function(){if(this.textboxElement===null&&this.textboxId!==null){this.textboxElement=document.getElementById(this.textboxId);}
if(this.dateDropdownElement===null&&this.dateDropdownId!==null){this.dateDropdownElement=document.getElementById(this.dateDropdownId);}
if(this.monthDropdownElement===null&&this.monthDropdownId!==null){this.monthDropdownElement=document.getElementById(this.monthDropdownId);}};mrO.searchInput.dateInputObject.prototype.sing=function(){alert("significance: "+this.significance+"\ntextboxId:"+this.textboxId+"\ndateDropdownId:"+this.dateDropdownId+"\nmonthDropdownId:"+this.monthDropdownId);};mrO.searchInput.dateInputObject.prototype.getSelectedDate=function(){var stringDate=null;this.ensureElements();if(this.textboxElement!==null){if(mrO.utils.isElementActive(this.textboxElement)){stringDate=this.textboxElement.value;}}else if(this.dateDropdownElement!==null&&this.monthDropdownElement!==null){if(mrO.utils.isElementActive(this.dateDropdownElement)&&mrO.utils.isElementActive(this.monthDropdownElement)){var day=this.dateDropdownElement[this.dateDropdownElement.selectedIndex].value;var monthAndYear=this.monthDropdownElement[this.monthDropdownElement.selectedIndex].value;stringDate=day+"/"+monthAndYear;}}
return stringDate;};mrO.searchInput.cityInputObject=function(significance){this.significance=significance;this.textboxId=null;this.cityDropdownId=null;this.hiddenSwitchId=null;this.hiddenACId=null;this.countryDropdownId=null;this.areaDropdownId=null;this.textboxElement=null;this.cityDropdownElement=null;this.hiddenSwitchElement=null;this.hiddenACElement=null;this.countryDropdownElement=null;this.areaDropdownElement=null;};mrO.searchInput.cityInputObject.prototype.ensureElements=function(){if(this.textboxElement===null&&this.textboxId!==null){this.textboxElement=document.getElementById(this.textboxId);}
if(this.cityDropdownElement===null&&this.cityDropdownId!==null){this.cityDropdownElement=document.getElementById(this.cityDropdownId);}
if(this.hiddenSwitchElement===null&&this.hiddenSwitchId!==null){this.hiddenSwitchElement=document.getElementById(this.hiddenSwitchId);}
if(this.hiddenACId===null&&this.textboxId!==null){this.hiddenACId="AC_IATA_"+this.textboxId;}else if(this.hiddenACId!==null&&this.hiddenACId==''){this.hiddenACId=null;}
if(this.hiddenACElement===null&&this.hiddenACId!==null){this.hiddenACElement=document.getElementById(this.hiddenACId);}
if(this.countryDropdownElement===null&&this.countryDropdownId!==null){this.countryDropdownElement=document.getElementById(this.countryDropdownId);}
if(this.areaDropdownElement===null&&this.areaDropdownId!==null){this.areaDropdownElement=document.getElementById(this.areaDropdownId);}};mrO.searchInput.cityInputObject.prototype.addInput=function(template,input){if(template==="textbox"){this.textboxId=input.textboxId;}
else if(template==="cityDropdown"){this.cityDropdownId=input.cityDropdownId;}
else if(template==="hiddenSwitch"){this.hiddenSwitchId=input.hiddenSwitchId;}
else if(template==="hiddenAC"){this.hiddenACId=input.hiddenACId;}
else if(template==="cascadingDropdown"){this.countryDropdownId=input.countryDropdownId;this.areaDropdownId=input.areaDropdownId;}};mrO.searchInput.cityInputObject.prototype.getSelectedIATA=function(){var iata=null;this.ensureElements();if(this.countryDropdownElement!==null&&this.areaDropdownElement!==null){if(this.areaDropdownElement.selectedIndex>=0){iata=this.areaDropdownElement[this.areaDropdownElement.selectedIndex].value;}}
else if(this.hiddenSwitchElement!==null){if(this.hiddenSwitchElement.value=="list"){iata=this.cityDropdownElement[this.cityDropdownElement.selectedIndex].value;}else if(this.hiddenSwitchElement.value=="text"){if(this.hiddenACElement!==null&&this.hiddenACElement.value!=""){iata=this.hiddenACElement.value;}else{iata=this.textboxElement.value;}}
else{alert("No viewstate set for "+this.significance+"!");}}
else{if(this.hiddenACElement!==null&&this.hiddenACElement.value!=""){iata=this.hiddenACElement.value;}else{iata=this.textboxElement.value;}}
return iata;};mrO.searchInput.prototype.registerElement=function(significance,id,template){if(id===null||id===''){return;}
id=(id==='')?null:id;template=(template==='')?null:template;if(mrO.isUndefined(this.elementInputs[significance])){this.elementInputs[significance]=new mrO.searchInput.elementObject(significance,id,template);}else{this.elementInputs[significance].id=id;this.elementInputs[significance].template=template;}};mrO.searchInput.prototype.registerElementSetting=function(significance,name,value){if(mrO.isUndefined(this.elementInputs[significance])){return;}
var inputObject=this.elementInputs[significance];inputObject[name]=value;};mrO.searchInput.prototype.registerCityInput=function(significance,inputs){if(mrO.isUndefined(this.cityInputs[significance])){this.cityInputs[significance]=new mrO.searchInput.cityInputObject(significance);}
if(mrO.isUndefined(significance)){return;}
if(mrO.isUndefined(inputs)){return;}
for(var input in inputs){if(true){this.cityInputs[significance].addInput(input,inputs[input]);}}};mrO.searchInput.prototype.registerDateInput=function(significance,textboxId,dateDropdownId,monthDropdownId){textboxId=(textboxId=='')?null:textboxId;dateDropdownId=(dateDropdownId=='')?null:dateDropdownId;monthDropdownId=(monthDropdownId=='')?null:monthDropdownId;this.dateInputs[significance]=new mrO.searchInput.dateInputObject(significance,textboxId,dateDropdownId,monthDropdownId);};mrO.searchInput.prototype.getCityIATA=function(significance){if(mrO.isDefined(this.cityInputs[significance])){return this.cityInputs[significance].getSelectedIATA();}else{return null;}};mrO.searchInput.prototype.getCity1IATA=function(){return this.getCityIATA("city1");};mrO.searchInput.prototype.getCity2IATA=function(){return this.getCityIATA("city2");};mrO.searchInput.prototype.getCity3IATA=function(){return this.getCityIATA("city3");};mrO.searchInput.prototype.getCity4IATA=function(){return this.getCityIATA("city4");};mrO.searchInput.prototype.getDate=function(significance){if(mrO.isDefined(this.dateInputs[significance])){return this.dateInputs[significance].getSelectedDate();}else{return null;}};mrO.searchInput.prototype.getDate1=function(){return this.getDate("date1");};mrO.searchInput.prototype.getDate2=function(){return this.getDate("date2");};mrO.searchInput.getBookingToggleInformation=function(){$('#getBookingWrapper').click(function(){if($('#moreInformation').is(":hidden")){$('#moreInformation').slideDown('slow',function(){$('#shutterWrapper').show();});}});$('#shutterWrapper').click(function(){if($('#moreInformation').is(":visible")){$('#moreInformation').slideUp('slow',function(){$('#shutterWrapper').hide();});}});};
