function getElementsByClass(className)
{
var classElements = new Array();
/* var alltags = document.all? document.all :
document.getElementsByTagName("*");
*/
var alltags = document.all? document.all.afpForm :
document.getElementsByTagName("*");
for (var i = 0; i < alltags.length; i++) {
// alert(alltags[i].name);
if (alltags[i].className == className) {
var idx = classElements.length;
classElements[idx] = alltags[i];
}
}
return classElements;
}
function getChildElements()
{
var res = new Array();
for (var i = 0; i < 2; i++) {
res[i] = new Array();
for (var j = 0; j < 4; j++) {
var k = i+1;
var l = j;
res[i][j] = document.getElementById("child" + k + "_" + l);
}
}
return res;
}
var childElements = null;
function setVisibleElement(element, isVisible)
{
element.style.display = isVisible? "" : "none";
}
function setVisible(elements, isVisible)
{
var elements = getElementsByClass("child");
var n = elements.length;
for (var i = 0; i < n; i++) {
setVisibleElement(elements[i], isVisible);
}
}
function OneChRoomIsVisible() {
var elements = getElementsByClass("child");
var n = elements.length;
for (var i = 0; i < n; i++) {
if (elements[i].style.display=="") {
return 1;
}
}
return 0;
}
function showChAgTitle(isVisible) {
if (document.getElementById('ChAgTitle')) {
document.getElementById('ChAgTitle').style.display=isVisible? "" : "none";
}
}
function showCnn(numCnn)
{
if (childElements == null) {
childElements = getElementsByClass("child");
}
showChAgTitle(0);
setVisible(childElements, (0 < numCnn));
}
function findElementById(elements, id)
{
var n = elements.length;
for (var i = 0; i < n; i++) {
if (elements[i].id == id) {
return elements[i];
}
}
return null;
}
function NumAdultsAndChildren(numAdults, numChildren)
{
this.adults = parseInt(numAdults);
this.children = parseInt(numChildren);
}
var roomTypes = new Array();
roomTypes[""] = new NumAdultsAndChildren(0, 0);
roomTypes["SGL"] = new NumAdultsAndChildren(1, 0);
roomTypes["TWN"] = new NumAdultsAndChildren(2, 0);
roomTypes["TWNC"] = new NumAdultsAndChildren(2, 1);
roomTypes["DBL"] = new NumAdultsAndChildren(2, 0);
roomTypes["DBLC"] = new NumAdultsAndChildren(2, 1);
roomTypes["FPL"] = new NumAdultsAndChildren(2, 2);
roomTypes["TRI"] = new NumAdultsAndChildren(3, 0);
roomTypes["QAD"] = new NumAdultsAndChildren(4, 0);
function showChildrenForRoomType(num, roomType)
{
var numChildren = roomTypes[roomType].children;
for (var i = 1; i <= 2; i++) {
var el = findElementById(childElements,
"child" + i + "_" + num);
if (el != null)
setVisibleElement(el, (i <= numChildren));
}
if (OneChRoomIsVisible()) {showChAgTitle(1);}
else {showChAgTitle(0);}
}
function validateNumPassengers(fnCont)
{
for (var i=0;i<document.afpForm.elements.length;i++) {
if (document.afpForm.elements[i].name=="CGI_NAME" && document.afpForm.elements[i].value=="airsearch" && document.afpForm.elements[i].checked) {
return true;
}
}
if(document.afpForm.rdcitycodeSelector.value == ""){
alert("Please select destination city!");
return false;	
} 
function getValueById(id, isSelection)
{
var node = document.getElementById(id);
var value = isSelection ? node.options[node.selectedIndex].value : node.value;
return value;
}
function getAirPtc(adtCode, childCode)
{
var numAdt = 0;
var numChd = 0;
for (var i = 1; i <= 3; i++) {
var code = getValueById("ptc" + i, false);
if (code == adtCode) {
numAdt = getValueById("numptc" + i, true);
}
if (code == childCode) {
numChd = getValueById("numptc" + i, true);
}
}
return new NumAdultsAndChildren(numAdt, numChd);
}
function getHotPtc()
{
var numAdt = 0;
var numChd = 0;
for (var i = 1; i <= 3; i++) {
var type = getValueById("roomtype" + i, true);
numAdt += roomTypes[type].adults;
numChd += roomTypes[type].children;
}
return new NumAdultsAndChildren(numAdt, numChd);
}
var airPtc = getAirPtc("ADT", "CNN");
var hotPtc = getHotPtc();
if ((airPtc.adults == 0)
|| (airPtc.adults > hotPtc.adults)
|| ((airPtc.adults + airPtc.children)
!= (hotPtc.adults + hotPtc.children))) {
alert("The size of your party and the number of beds selected are not equal.");
return false;
}
return fnCont();
}