var loaded =false;
var blurpopup = 0;
var lib = null;


var aDate=new Date();
var aYear=aDate.getYear();
if (aYear<1000) aYear+=1900;
var aMonth=aDate.getMonth()+1;
if (aMonth<10) aMonth="0"+aMonth;
var aDay=aDate.getDate();
if (aDay<10) aDay="0"+aDay;
var serverDate = aMonth+"/"+aDay+"/"+aYear;
var serverDate = top.window.serverDate;

var keyBlur = 0;
var g_target;
var g_Calendar;


var miniBooking = new MiniBM();
var miniCalendar = new MiniCalendar();
var m_Calendar = new miniCalendar.Calendar();

//adding head tag 
function pageCheck(){
if(document.getElementsByTagName("head").length<1)
{
var headEle = document.createElement("head");
document.getElementsByTagName("html")[0].appendChild(headEle);
}
}
pageCheck();

function MiniBM(){

this.bookingForm = bookingForm;

function bookingForm(val){

if(val == 'FHsel' && document.getElementById('FH').checked == false){
divOff('flightHotel');
val = 'FOsel'
}

if(val == 'FOsel' && document.getElementById('FH').checked == true){
val = "FHsel"
}
divOff('car');
divOff('cruise');
divOff('flight');
divOff('flightHotel'); 
divOff('hotel');
divOff('CruiseContact');
divOff('weekend');
divOff('bm');
divOff('bmComboOffer');
if(val=='CRsel')
divOn('CruiseContact');

switch(val){
case 'FOsel': 
divOn('flight');
divOn('bmComboOffer');
document.getElementById('lnk_Option').innerHTML = "<a href='http://travel.aol.com/flights'>More Flight Options</a>"
try{
document.getElementById('FOform').id
}catch(e){
loaded=false;
dhtmlLoadScript(JSpath+'flight.js');
afterFlightLoad();
}
break;

case 'FHsel': 
divOn('flightHotel');
divOn('bmComboOffer');
document.getElementById('lnk_Option').innerHTML = "<a href='http://travel.aol.com/flights'>More Flight Options</a>"
try{
document.getElementById('FHform').id
}catch(e){
loaded=false;
dhtmlLoadScript(JSpath+'flightHotel.js');
afterFlightHotelLoad();
}
break;
case 'HOsel': 
divOn('hotel');
document.getElementById('lnk_Option').innerHTML = "<a href='http://travel.aol.com/hotels'>More Hotel Options</a>"
try{
document.getElementById('HOform').id
}catch(e){
loaded=false;
dhtmlLoadScript(JSpath+'hotel.js');
afterHotelLoad();
}
break;
case 'COsel': 
divOn('car');
document.getElementById('lnk_Option').innerHTML = "<a href='http://travel.aol.com/car-rentals'>More Car Rental Options</a>"
try{
document.getElementById('COform').id
}catch(e){
loaded=false;
dhtmlLoadScript(JSpath+'car.js');
afterCarLoad();
}
break;

case 'CRsel': 
divOn('cruise');
document.getElementById('lnk_Option').innerHTML = "<a href='http://travel.aol.com/cruises'>More Cruise Options</a>"
try{
document.getElementById('CRform').id
}catch(e){
loaded=false;
dhtmlLoadScript('http://www.travelocity.com/js/cbcruise/0,,,00.js');
afterAPILoad();
}
break;
case 'WEsel': 
divOn('weekend');
document.getElementById('lnk_Option').innerHTML = "<a href='http://aolservice.lmdeals.com/'>More Last-Minute Options</a>"
try{
document.getElementById('WEform').id
}catch(e){
loaded=false;
dhtmlLoadScript(JSpath+'weekend.js');
afterWeekendLoad();
}
break;
}
}
}

function afterCalendarLoad(){
if(typeof loaded == 'undefined' || !loaded){
window.setTimeout('afterCalendarLoad()', 1);
}
else{
getCal();
}
}

function afterValidateLoad(id){
if(typeof loaded == 'undefined' || !loaded)
{
window.setTimeout('afterValidateLoad("'+id+'")',1)
}
else
{
lib = new BBLib();
lib.validate(document.getElementById(id));
}  
}

function afterFlightLoad(){
if(typeof loaded == 'undefined' || !loaded)
{
window.setTimeout('afterFlightLoad()', 1);
}
else
{
document.getElementById('flight').innerHTML = appendFlight();
initFlight();
}
}

function afterFlightHotelLoad(){
if(typeof loaded == 'undefined' || !loaded)
{
window.setTimeout('afterFlightHotelLoad()', 1);
}
else
{
document.getElementById('flightHotel').innerHTML = appendFlightHotel();
initFlightHotel();
}
}

function afterHotelLoad(){
if(typeof loaded == 'undefined' || !loaded)
{
window.setTimeout('afterHotelLoad()', 1);
}
else
{
document.getElementById('hotel').innerHTML = appendHotel();
initHotel();
}
}

function afterCarLoad(){
if(typeof loaded == 'undefined' || !loaded)
{
window.setTimeout('afterCarLoad()', 1);
}
else
{
document.getElementById('car').innerHTML = appendCar();
initCar();
}
}

function afterAPILoad(){
if(typeof destSelectList == 'undefined'){
window.setTimeout('afterAPILoad()', 1);
}
else{
dhtmlLoadScript(JSpath+'cruise.js');
afterCruiseLoad();
}
}

function afterCruiseLoad(){
if(typeof loaded == 'undefined' || !loaded)
{
window.setTimeout('afterCruiseLoad()', 1);
}
else
{
document.getElementById('cruise').innerHTML = appendCruise();
initCruise();
}
}

function afterWeekendLoad(){
if(typeof loaded == 'undefined' || !loaded)
{
window.setTimeout('afterWeekendLoad()', 1);
}
else
{
document.getElementById('weekend').innerHTML = appendWeekend();
initWeekend();
}
}

function dhtmlLoadScript(url)
{
var e = document.createElement("script");
e.src = url;
e.type="text/javascript";
document.getElementsByTagName("head")[0].appendChild(e);
}

function validateFormSubmit(formObj){
try{
lib.validate(formObj);
}catch(e){
loaded = false;
dhtmlLoadScript(JSpath+'validate.js');
afterValidateLoad(formObj.id);

} 
}

function divOff(id)
{
if(document.getElementById(id) != null)
{
document.getElementById(id).style.display = 'none';
}
}

function divOn(id)
{
if(document.getElementById(id) != null)
{
document.getElementById(id).style.display = 'inline';
}
}


/*SELECT BOX OPTIONS POPULATION*/

function fillSel(selObj,startVal,endVal){
if(startVal == 12){
var inc=0;
var m ='am'
if(endVal==1){
selObj.options[0] = new Option('Anytime','Anytime')
selObj.options[1] = new Option('Morning','Morning')
selObj.options[2] = new Option('Afternoon','Afternoon')
selObj.options[3] = new Option('Evening','Evening')
selObj.options[4] = new Option('--------------------','Anytime')
}
for(i=5,k=0,j=12;j<13;j++,i++,k++){
if(endVal == 1){str=j+':00'+m;val = j+':00'+m;}
else{str=j+m;val=k;i=k;}
selObj.options[i] = new Option(str,val)
if(j == 11){inc++;m='pm';}if(inc==2)break;if(j == 12)j=0;
}
if(endVal == 0)selObj.options.selectedIndex = 10;
return;
}
var index=1;
selObj.options[0] = new Option('?','');
if(startVal == 1){
selObj.options[1] = new Option('<1','0');
index =2;
}
for(fill=startVal;fill<=endVal;fill++){
selObj.options[index] = new Option(fill,fill)
index++;
}
}


function setMinorState(total,selected,para,suffix){
if(selected > 0)
document.getElementById(para).style.display = "block"
else
document.getElementById(para).style.display = "none"
var num;
if(suffix == ''){
num =0;
selected--;
}
else {
num = 1;
}

for(;num<=total;num++){
var currentObj = 'minorsAge'+num+suffix;
var currentObjLbl = currentObj+'lbl' 
if(num <= selected){
document.getElementById(currentObj).disabled = false;
document.getElementById(currentObj).parentNode.style.display = "inline"
document.getElementById(currentObj).style.display = "inline"
document.getElementById(currentObjLbl).style.display = "inline"
}
else{
document.getElementById(currentObj).disabled = true;
document.getElementById(currentObj).parentNode.style.display = "none"
document.getElementById(currentObj).style.display = "none"
document.getElementById(currentObjLbl).style.display = "none"
}
}
}

function setRoomState(selected,suffix){
var num;
for(num = 2;num<5;num++){
if(num <= selected){
document.getElementById('adult'+num+suffix).disabled = false;
if(suffix == '-FH')
document.getElementById('senior'+num+suffix).disabled = false;
document.getElementById('child'+num+suffix).disabled = false;
document.getElementById('room'+num+suffix).style.display = "inline"
setMinorState(5,document.getElementById('child'+num+suffix).value,'bm'+num+suffix,'Room'+num+suffix)

}
else{
document.getElementById('adult'+num+suffix).disabled = true;
if(suffix == '-FH')
document.getElementById('senior'+num+suffix).disabled = true;
document.getElementById('child'+num+suffix).disabled = true;
document.getElementById('room'+num+suffix).style.display = "none"
setMinorState(5,0,'bm'+num+suffix,'Room'+num+suffix)

}
}
}

function MiniCalendar(){

errorMessage            = this.errorMessage           
                
this.initCalendars = initCalendars;
this.Calendar  = Calendar;
this.handleClick = handleClick;

var g_startDay = 0// 0=sunday, 1=monday
var calHeight = 115;
if (staticDomain === undefined) {
var staticDomain = "";
}

function handleClick(eve){
    try{
        handleDocumentClick(eve)
    }catch(err){}
}

function Calendar(){
g_Calendar = this;
var tmpLayer = document.getElementById('container');
this.containerLayer = tmpLayer;
}

Calendar.prototype.show = function(event, target){
if (this.containerLayer!=null) {
if (this.containerLayer.style.visibility=='visible'){
document.getElementById('ifrm_cal').style.display = 'none'
document.getElementById('ifrm').style.display = 'none'
this.containerLayer.style.visibility='hidden';
return;
}
var obj = document.getElementById(target);
document.getElementById('ifrm').style.left = (findX(obj))+'px';
this.containerLayer.style.left = (findX(obj))+'px';
document.getElementById('ifrm').style.top = findY(obj)+20+'px';
this.containerLayer.style.top = findY(obj)+20+'px';

this.target = target;
g_target = this.target;
try{
getCal();
}catch(e){
loaded=false;
dhtmlLoadScript(JSpath+'DynamicCalendar.js');
afterCalendarLoad();
}
this.containerLayer.style.visibility='visible';
document.getElementById('ifrm_cal').style.display = 'block'
document.getElementById('ifrm').style.display = 'block'
justClicked = true;
doTimeout('justClicked');
}
}

function doTimeout(name){
window.setTimeout(name + '= false',100);
return;
}

function findX(obj){
var curleft=0;
var IEcal =0;
while (obj.offsetParent){
curleft+=obj.offsetLeft;
obj=obj.offsetParent;
}
curleft+=obj.offsetLeft;
if(document.all && document.getElementById){
IEcal = document.body.offsetLeft;
}
return curleft-IEcal;
}

function findY(obj){
var curtop = 0;
while(obj.offsetParent){
curtop += obj.offsetTop;
obj=obj.offsetParent;
}
curtop+=obj.offsetTop;
return curtop;
}

function getTarget(){
return g_Calendar.target;
}

Calendar.prototype.hide = function(){
if (this.containerLayer!=null) {
this.containerLayer.style.visibility='hidden';
document.getElementById('ifrm_cal').style.display = 'none'
document.getElementById('ifrm').style.display = 'none'
divOff('bb_bkeyword');
divOn('bb_bkeyword');
}
}

function initCalendars(calLists){
for(var c in calLists){
for(var x=0;x<calLists[c].length;x++){
buildDate(parseInt(c,10),calLists[c][x]);
}
}
}

function buildDate(num,t){
var adjDate = new Date(serverDate);
adjDate.setDate(adjDate.getDate()+num);

var d = ((adjDate.getMonth()+1)<10?'0'+(adjDate.getMonth()+1):(adjDate.getMonth()+1)) + '/' + (adjDate.getDate()<10?'0'+adjDate.getDate():adjDate.getDate()) + '/' + adjDate.getFullYear();
if(document.getElementById(t))
document.getElementById(t).value = d;

}
}

