// Javascript to support ian.com hotel search - hotelsearch.fnc    var defaultAdults="2";    var cellStyle=" class='IANFormhdr'";    var childHelp="Please provide the ages of children in each room. Children's ages should be their age at the time of travel.";    var adultHelp="";    var textRooms="Rooms:";    var textAdults="Adults:";    var textChildren="Children:";    var textChildError="Please specify the ages of all children.";    var pad='<img src="http://travel.ian.com/images/p.gif" width="5" height="1">';    // NOTE: Question marks ("?") get replaced with a numeric value    var textRoomX="Room ?:";    var textChildX="Child ?:";    var adultsPerRoom=new Array(defaultAdults);    var childrenPerRoom=new Array();    var childAgesPerRoom=new Array();    var numRooms=1;    var maxChildren=0;    function travelNowize() {        // Kit: convert field values to proper dates for ian       var adt = new Date(Date.parse(document.forms['IANForm'].arrDate.value));       var ddt = new Date(Date.parse(document.forms['IANForm'].depDate.value));        document.forms['IANForm'].departureDay.value = ddt.getDate();        document.forms['IANForm'].departureMonth.value = ddt.getMonth();        document.forms['IANForm'].arrivalDay.value = adt.getDate();        document.forms['IANForm'].arrivalMonth.value = adt.getMonth();    }    function group() {        if (document.IANForm.numberOfRooms.selectedIndex == 8) {            window.location="http://travel.ian.com/index.jsp?pageName=groups&cid=252688&locale=en_US";            return false;        } else {            travelNowize();            return true;        }    }    function groupplus() { //Infodog: Advanced search        if (document.IANForm.numberOfRooms.selectedIndex == 8) {            window.location="http://travel.ian.com/index.jsp?pageName=groups&cid=252688&locale=en_US";            return false;            }        else {            with (document.IANForm) {                streetAddress.value="";                metroAddress.value="";                el=address.value.split(',');                if (el.length>2) {                    if (dodistance.checked==true)                        streetAddress.value=el[0];                    k=1;                    }                else k=0;                for (i=k;i<el.length;i++) {                    metroAddress.value += el[i];                    if (i<el.length-1)                        metroAddress.value +=',';                    }//                alert(streetAddress.value+';'+metroAddress.value);               adt = new Date(Date.parse(arrDate.value));               ddt = new Date(Date.parse(depDate.value));               thismo = new Date().getMonth();               if (adt.getMonth()<thismo)                   arrivalMonth.value=adt.getMonth()+12;               else                   arrivalMonth.value=adt.getMonth();               arrivalDay.value=adt.getDate();               if (ddt.getMonth()<thismo)                   departureMonth.value=ddt.getMonth()+12;               else                   departureMonth.value=ddt.getMonth();               departureDay.value=ddt.getDate();               }            return true;            }        }    function setChildAge(room, child, age) {        if (childAgesPerRoom[room] == null) {            childAgesPerRoom[room] = new Array();        }        childAgesPerRoom[room][child] = age;    }    function setNumAdults(room, numAdults) {        adultsPerRoom[room] = numAdults;    }    function setNumChildren(room, numChildren) {        childrenPerRoom[room] = numChildren;        refresh();    }    function setNumRooms(x) {        numRooms = x;        for (i = 0; i < x; i++) {            if (adultsPerRoom[i] == null) {                adultsPerRoom[i] = 2;            }            if (childrenPerRoom[i] == null) {                childrenPerRoom[i] = 0;            }        }        refresh();    }    function renderRoomSelect() {        var x = '';        x += '<select name="numberOfRooms" style="width:50px;" onchange="setNumRooms(this.options[this.selectedIndex].value);">';        for (var i = 1; i < 9; i++) {            x += '<option value="'+i+'"'+(numRooms == i ? ' selected' : '')+'>' + i;        }        x += '<option value="9"'+(numRooms == 9 ? ' selected' : '')+'>9+';        x += '</select>';        return x;    }    function refresh() {        maxChildren = 0;        for (var i = 0; i < numRooms; i++) {            if (childrenPerRoom[i] > maxChildren) {                maxChildren = childrenPerRoom[i];            }        }        var x = '';        if (adultHelp.length > 0) {            x = adultHelp + "<p>\n";        }        if (numRooms > 8) {            x += textRooms;            x += renderRoomSelect();        } else {            x += '<table border="0" cellspacing="2" cellpadding="0">\n';            x += '<tr><td'+cellStyle+'>'+textRooms+pad+'</td>';            if (numRooms > 1) {                x += '<td'+cellStyle+'>&nbsp;</td>';            }            x += '<td'+cellStyle+'><nobr>'+textAdults+pad+'</nobr></td><td'+cellStyle+'><nobr>'+textChildren+pad+'</nobr></td></tr>\n';            for (var i = 0; i < numRooms; i++) {                x += '<tr><td'+cellStyle+'>';                if (i == 0) {                    x += renderRoomSelect();                } else {                    x += '&nbsp;';                }                x += '</td>';                if (numRooms > 1) {                    x += '<td'+cellStyle+'><nobr>'+getValue(textRoomX, i+1)+pad + '</nobr></td>';                }                x += '<td'+cellStyle+'>';                x += buildSelect('room-' + i + '-adult-total', 'setNumAdults(' + i + ', this.options[this.selectedIndex].value)', 1, 4, adultsPerRoom[i]);                x += '</td><td'+cellStyle+'>';                x += buildSelect('room-' + i + '-child-total', 'setNumChildren(' + i + ', this.options[this.selectedIndex].value)', 0, 6, childrenPerRoom[i]);                x += '</td></tr>\n';            }            x += '</table>\n';            var didHeader = false;            for (var i = 0; i < numRooms; i++) {                if (childrenPerRoom[i] > 0) {                    if (!didHeader) {                        x += '<table border="0" cellpadding="0" cellspacing="2">\n';                        x += '<tr><td'+cellStyle+' colspan="'+(maxChildren+1)+'">';                        x += '<img src="/images/p.gif" width="1" height="5"><br>';                        x += childHelp;                        x += '<img src="/images/p.gif" width="1" height="5"><br>';                        x += '</td></tr>\n<tr><td'+cellStyle+'>&nbsp;</td>';                        for (var j = 0; j < maxChildren; j++) {                            x += '<td'+cellStyle+'><nobr>'+getValue(textChildX, j+1)+pad+'</nobr></td>\n';                        }                        didHeader = true;                    }                    x += '</tr>\n<tr><td'+cellStyle+'><nobr>'+getValue(textRoomX, i+1)+pad+'</nobr></td>';                    for (var j = 0; j < childrenPerRoom[i]; j++) {                        x += '<td'+cellStyle+'>';                        var def = -1;                        if (childAgesPerRoom[i] != null) {                            if (childAgesPerRoom[i][j] != null) {                                def = childAgesPerRoom[i][j];                            }                        }                        x += '<select name="room-'+i+'-child-'+j+'-age" style="width:50px;" onchange="setChildAge('+i+', '+j+', this.options[this.selectedIndex].value);">';                        x += '<option value="-1"'+(def == -1 ? ' selected' : '')+'>-?-';                        x += '<option value="0"'+(def == 0 ? ' selected' : '')+'>&lt;1';                        for (var k = 1; k <= 18; k++) {                            x += '<option value="'+k+'"'+(def == k ? ' selected' : '')+'>'+k;                        }                        x += '</td>';                    }                    if (childrenPerRoom[i] < maxChildren) {                        for (var j = childrenPerRoom[i]; j < maxChildren; j++) {                            x += '<td'+cellStyle+'>&nbsp;</td>';                        }                    }                    x += '</tr>\n';                }            }            if (didHeader) {                x += '</table>\n';            }        }        document.getElementById("hot-search-params").innerHTML = x;    }    function buildSelect(name, onchange, min, max, selected) {        var x = '<select name="' + name + '" style="width:50px;"';        if (onchange != null) {            x += ' onchange="' + onchange + '"';        }        x +='>\n';        for (var i = min; i <= max; i++) {            x += '<option value="' + i + '"';            if (i == selected) {                x += ' selected';            }            x += '>' + i + '\n';        }        x += '</select>';        return x;    }    function validateGuests(form) {        if (numRooms < 9) {            var missingAge = false;            for (var i = 0; i < numRooms; i++) {                var numChildren = childrenPerRoom[i];                if (numChildren != null && numChildren > 0) {                    for (var j = 0; j < numChildren; j++) {                        if (childAgesPerRoom[i] == null || childAgesPerRoom[i][j] == null || childAgesPerRoom[i][j] == -1) {                            missingAge = true;                        }                    }                }            }            if (missingAge) {                alert(textChildError);                return false;            } else {                return true;            }        } else {            return true;        }    }    function submitGuestInfoForm(form) {        if (!validateGuests(form)) {            return false;        }        return true;    }    function getValue(str, val) {        return str.replace(/\?/g, val);    }