//© 2010 Starwood Hotels & Resorts Worldwide, Inc.
//  All rights reserved.
//--------------------------------------------------------------------------------------------
// E R R O R    H A N D L I N G -- R A T E L I S T
// -------------------------------------------------------------------------------------------
var errorArray = new Array();
var showErrArray = '';
var allowedCharacters = "- ";
//------------------------------------------------------
// function to determine whether or not the form is in good enough condition to submit
function okForm(f, action, pageType) {
    getRoomList();
    okCheckDates(f);
    getLengthOfStay(f.ciDate.value, f.coDate.value);
    readyCheckBox(f.wheelchairHolder, f.wheelchairPreference);

    // FOR ALOFT HOTELS LIST CHECK IF THAT DROPDOWN IS PRESENT AND VALIDATE IT
    if(document.getElementById('selectHotelsDropDown')) {
        checkSelectedHotel(f);     
    }

    checkForErrors(f, action, pageType);
}

function checkSelectedHotel(f) {
    if(f.propertyID.value == '' || f.propertyID.value == null) {
        setErrCode(35);
        setErrCode(36);
    }
}

function okNumericFields(fo) {

    // 1. check for errors in the numeric fields : SET and ATA number
    if (fo.corporateAccountNumber == null || fo.iATANumber == null)
        return true;
    var set = fo.corporateAccountNumber.value;
    var ata = fo.iATANumber.value;
    ata=ata.replace(/^\s+/g, '').replace(/\s+$/g, '');
    set = stripCharsInBag(set, allowedCharacters);
    if (set != '') {
        if (! isInteger(set)) {
            setErrCode(29);
            setErrCode(26);
        }
    }
    if (ata != '') {
        if (! isInteger(ata)) {
            setErrCode(28);
            setErrCode(27);
        }
    }

    // 2. check if both promo code & rate plan are filled
    var pro = fo.promotionCode.value;
    //alert("promotionCode: " + pro + " || ratePlanName: " + fo.ratePlanName.options[fo.ratePlanName.selectedIndex].value);
    var rate = fo.ratePlanName.options[fo.ratePlanName.selectedIndex].value;
    if (pro != '' && rate != '') {
        setErrCode(30);
        setErrCode(25);
        setErrCode(24);
    }

    // 3. check if both promo code and SET number  are entered
    if(set !='' && pro !=''){
        setErrCode(37);
        setErrCode(26);
        setErrCode(25);
    }

    // 4. check for both rateplan and SET number values
    if (set != '' && rate != '') {
        setErrCode(31);
        setErrCode(26);
        setErrCode(24);
    }
}

Array.prototype.contains = function (element) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == element) {
            return true;
        }
    }
    return false;
};
