function isBrowserSupp() {
    version =  parseFloat( navigator.appVersion );

    if ( ( version >= 2.0 ) && ( version < 2.1 ) && ( navigator.appName.indexOf( "Netscape" ) != -1 ) ) {
        return false;
    } else {
        return true;
    }

    return true;
}

function isLeapYear( yrStr ) {
    var leapYear = false;
    var year = parseInt( yrStr, 10 );
    // every fourth year is a leap year
    if ( year % 4 == 0 ) {
        leapYear = true;
        // unless it's a multiple of 100
        if( year % 100 == 0 ) {
            leapYear = false;
            // unless it's a multiple of 400
            if( year % 400 == 0 ) {
                leapYear=true;
            }
        }
    }
    return leapYear;
}

function getDaysInMonth( mthIdx, YrStr ) {
    var maxDays = 31
    if( mthIdx == 1 ) {
        if( isLeapYear( YrStr ) ) {
            maxDays=29;
        } else {
            maxDays=28;
        }
    }

    if( mthIdx == 3 || mthIdx == 5 || mthIdx == 8 || mthIdx == 10 ) {
        maxDays=30;
    }
    return maxDays;
}

function adjustDate( mthIdx, Dt ) {
    var value = 0;

    var today = new Date()
    var theYear = parseInt( today.getYear(), 10 )

    if( mthIdx < today.getMonth() ) {
        theYear = ( parseInt( today.getYear(), 10 ) + 1 )
    }
    if( theYear < 100 ) {
        theYear = "19" + theYear
    } else {
        if( ( theYear - 100 ) < 10 ) {
            theYear = "0" + ( theYear - 100 )
        } else {
            theYear = ( theYear - 100 ) + ""
        }
        theYear = "20" + theYear
    }

    var numDays = getDaysInMonth( mthIdx, theYear );

    if( mthIdx == 1 ) {
        if( Dt.options.selectedIndex + 2 < numDays ) {
            return 0;
        } else {
            if( Dt.options.selectedIndex + 1 > numDays) {
                Dt.options.selectedIndex=numDays - 1;
            }
            //check for leap year
            if( (Dt.options.selectedIndex + 1) == numDays ) {
                return 1;
            } else {
                return 4;
            }
        }
    }

    if( Dt.options.selectedIndex + 2 < numDays ) {
        value = 0;
    } else {
        if ( Dt.options.selectedIndex + 1 > numDays ) {
            Dt.options.selectedIndex--;
            value = 3;
        } else if ( Dt.options.selectedIndex + 1 == numDays ) {
            //index is 31 or 30
            value = 2;
        } else {
            value = 4;
        }
    }
    return value;
}

function amadChange( inM, inD, outM, outD ) {
    if ( !isBrowserSupp() ) {
        return;
    }

    var res = adjustDate( inM.options.selectedIndex, inD );
    if( res != 0 ) {
           outD.options.selectedIndex = 0;
           if ( inM.options.selectedIndex == 11 ) {
                outM.options.selectedIndex = 0
           } else if( res == 4 ) {
                outM.options.selectedIndex=inM.options.selectedIndex + 1;
                outD.options.selectedIndex = 0;
           } else {
                outM.options.selectedIndex=inM.options.selectedIndex + 1;
                outD.options.selectedIndex = 1;
           }
    } else {
        outM.options.selectedIndex = inM.options.selectedIndex;
        if (outD.options.selectedIndex <= inD.options.selectedIndex) {
            outD.options.selectedIndex = inD.options.selectedIndex + 2;
        }
    }
    return;
}

function dmddChange( outM, outD ) {
    if ( !isBrowserSupp() ) {
        return;
    }

    adjustDate( outM.options.selectedIndex, outD );
    return;
}

function submitForm() {
	var a = document.hotSearch.arrival.value;
	a = a.split('/');
	var d = document.hotSearch.departure.value;
	d = d.split('/');
	document.hotSearch.zmonth.value = a[0];
	document.hotSearch.doa_mm.value = a[0];
	document.hotSearch.zday.value =   a[1];
	document.hotSearch.doa_dd.value = a[1];
	document.hotSearch.zyear.value  = a[2];
	document.hotSearch.doa_yy.value = a[2];
	document.hotSearch.dod_mm.value = d[0];
	document.hotSearch.dod_dd.value = d[1];
	document.hotSearch.dod_yy.value = d[2];

	if ($("input[@name='lodging']:checked").val() == 'bandb') {
		document.hotSearch.action = "http://www.webervations.com/magic-scripts/associations/ameliaisland_display.asp";
	} else {
		document.hotSearch.action = "http://www.res99.com/nexres/search/search_results.cgi";
	}
	
	document.hotSearch.submit();
}

function checkAvailability(x){
	if (x == "hotel") {
		document.hotSearch.action="http://travel.neworleansonline.com/nexres/search/search_results.cgi";
		document.hotSearch.submit();
		}
	else if (x == "bandb") {
		url = "http://www.webervations.com/magic-scripts/associations/neworleans.asp?numberOfAdults=2&arrivalDay=";
		url += document.getElementById('doa_dd').value;
		url += "&arrivalMonth=" + document.getElementById('doa_mm').value;
		url += "&departureDay=" + document.getElementById('dod_dd').value;
		url += "&departureMonth=" + document.getElementById('dod_mm').value;  
		window.location.href = url;
		}
	}

function bookingMode(x) {
	
	if (x == 'webervations') {
		
		document.hotSearch.action = "";
		
		
	} else {
	
		document.hotSearch.action = "";
		
	}
	
}