
function ta_writeLayer(layerName) {
    if((navigator.appName.indexOf("Netscape") > -1) && (navigator.appVersion.indexOf("4") > -1)) {
        // layers are disabled
    } else
        document.write("<div id=\""+layerName+"\">");
}

function ta_writeLayerEnd() {
    if((navigator.appName.indexOf("Netscape") > -1) && (navigator.appVersion.indexOf("4") > -1)) {
        // layers are disabled
    } else
        document.write("</div>");
}

function ta_getValue(selectField) {
    if (selectField) {
        var selected = selectField.selectedIndex;
        if (selected != -1) {
            return selectField.options[selected].value;
        }
    }
    return null;
}

function ta_getIntValue(selectField) {
    if (selectField) {
        var selected = selectField.selectedIndex;
        if (selected != -1) {
            var value = selectField.options[selected].value;
            if (value > -10000000 && value < 10000000)
                return new Number(value);
        }
    }
    return new Number(0);
}

function ta_checkSubmitCampaign() {
    if (document.images) {
        if (initialized == false)
            return false;
        if(ta_force == true)
            window.document.searchForm.force.value = 'true';
        else if(ta_force == false)
            window.document.searchForm.force.value = 'false';
        return true;
    } else
        return false;
}

function ta_checkSubmit() {
    if (document.images) {
        if (initialized == false)
            return false;
        if (isNothingSelected()) {
            if (countDiff() > 7) {
                popUp(""+popUpURL+"20");
                return false;
            }
        } else if (countDiff() > 30) {
            popUp(""+popUpURL+"21");
            return false;
        }
        if (ta_month_a == 0 && ta_day_a < ta_1st_search_day) {
        	popUp(""+popUpURL+"22");
        	return false;
        }
        if(ta_force == true)
            window.document.searchForm.force.value = 'true';
        else if(ta_force == false)
            window.document.searchForm.force.value = 'false';
        if(!isLengthSelected()) {
            popUp(""+popUpURL+"3");
            return false;
        }if(ta_hasMaxPrice) {
            if(!isInteger(window.document.searchForm.ts_max_price.value)) {
                popUp(""+popUpURL+"23");
                return false;
            }
        }
        return true;
    } else
        return false;
}

function isInteger(value) {
    if(value == "")
        return true;
    else
        return (parseInt(value) == value);
}


function ta_searchBodyOnLoad() {
    if (ta_adaEn) {
        // set area id
        ta_fillAreaVal();
        // build dest menu
        ta_updateDependent('De',document.searchForm.ts_area,document.searchForm.ts_dest);
        // set dest id
        ta_fillDestVal();
        if (ta_accEn) {
            // build acc menu
            ta_updateDependent('Ac',document.searchForm.ts_dest,document.searchForm.ts_accommodation);
            ta_fillAccVal();
        }
    }
    if (ta_iataEn) {
        ta_fillIataVal();
    }
    fillInStoredGroupValues();

    // build date menu
    if (ta_dateFieldsEn)
        setupDateFields();

    // set all values
    fillInStoredValues();
    // set date fields
    if (ta_dateFieldsEn)
        fillInStoredDateFields();

    ta_handleChildrenMenu();

    if (ta_adaEn) {
        // handle dest attributes
        handleDestinationMenu();
        if (ta_accEn) {
            // handle acc attributes
            handleAccommodationMenu();
        }
    }
    if (ta_roomsEn) {
        ta_initRooms();
        ta_fillRoomCount();

        if (ta_discard_rooms) {
            // force limited to 1 room
            if (_ta_isShareable(document.searchForm.ts_adults, document.searchForm.ts_ch_2)) {
                //ok
            } else {
                document.searchForm.ts_room_count.selectedIndex = 0;
            }
        }

        ta_initSetting();

        if (ta_settlingEn)
            ta_fillRoomCombi();
        ta_rs_initDone();
    }
    ta_saveCurrentGroup();

    ta_checkGroupValidity();

    if (ta_settlingEn) {
        // handle settling menu
        ta_handleSettlingMenu();
    }

    initialized = true; //enable search
    ta_flagInitialized();
    return;
}

function ta_flagInitialized() {
    if(document.searchForm.initialized) {
        document.searchForm.initialized.value = "true";
    }
}

// for group
function ta_childrenMChange(saveElement) {
    ta_handleChildrenMenu();
    if(document.searchForm.ts_with_children.checked == false) {
        document.searchForm.ts_ch_2.selectedIndex=0;
        saveGroupValue(document.searchForm.ts_ch_2);
        if (document.searchForm.ts_ch_gr1) {
            document.searchForm.ts_ch_gr1.selectedIndex=0;
            saveGroupValue(document.searchForm.ts_ch_gr1);
        }
        if (document.searchForm.ts_ch_gr2) {
            document.searchForm.ts_ch_gr2.selectedIndex=0;
            saveGroupValue(document.searchForm.ts_ch_gr2);
        }
        if (document.searchForm.ts_ch_gr3) {
            document.searchForm.ts_ch_gr3.selectedIndex=0;
            saveGroupValue(document.searchForm.ts_ch_gr3);
        }
        if (document.searchForm.ts_ch_gr4) {
            document.searchForm.ts_ch_gr4.selectedIndex=0;
            saveGroupValue(document.searchForm.ts_ch_gr4);
        }
    }
    if (ta_roomsEn || ta_settlingEn)
        ta_updateRSIfNeeded();
    saveGroupValue(saveElement);
}

function ta_groupChange(saveElement) {
    ta_checkGroupValidity();
    if (ta_roomsEn || ta_settlingEn)
        ta_updateRSIfNeeded();
    saveGroupValue(saveElement);
}

// DEPRECATED

function childrenMChange(saveElement) {
    return ta_childrenMChange(saveElement);
}


function checkSubmit() {
    return ta_checkSubmit();
}

function updateDependent(prefix, from, to) {
    return ta_updateDependent(prefix, from, to);
}

function forwardToAllPage(ctrl) {
    return ta_forwardToAllPage(ctrl);
}

function ta_updateDependent(prefix, from, to) {
    var value = from.options[from.selectedIndex].value;

    if (value != "") {
        var names = eval(prefix + "Nfixed").concat(eval(prefix + "N" + value));
        var values = eval(prefix + "Ifixed").concat(eval(prefix + "I" + value));

        var newLength = values.length;
        var oldLength = to.options.length;

        ta_empty(to);

        for(var i = 0; i < newLength; i++) {
            var name = names[i];
            value = values[i];
            var newOption = new Option(name,value,false,false);
            to.options[i] = newOption;
        }
        to.selectedIndex = 0;
        return false;
    }
}

function ta_empty(selectField){
    while(selectField.length > 0){
        selectField.options[selectField.length - 1] = null;
    }
}

function ta_forwardToAllPage(ctrl) {
   // todo fix for ss
   var URL = "";
   if((ta_getValue(ctrl) != "99") && (ta_getValue(ctrl) != "98")) { //shared
        if(ta_sunski) {
            URL = "/shopframe.asp?page=3&e=9";
        } else {
            URL = "/shopframe.asp?page=2&e=9"; //machine specific | e - because we must know what message to print!
        }
        window.location.href = URL;
        location.replace(URL);
   }
}

function ta_openWindow(URL, name, width, height, scrollbars, resizable) {
	window.open(URL, name, 'toolbar=0,scrollbars='+scrollbars+',location=0,statusbar=0,menubar=0,resizable='+resizable+',width='+width+',height='+height+',left = 100,top = 125');
}

function openWindowExactSize(URL, name, width, height) {
    ta_openWindow(URL, name, width, height, 1, 1);
}

function openWindow(URL) {
    ta_openWindow(URL, 'popup', 450, 530, 0, 0);
}

function popUp(URL) {
    ta_openWindow(URL, 'popup', 350, 200, 0, 0);
}

function URLToParentWindow(URL) {
    if (window.parent) {
        window.parent.location = URL;
    } else {
        window.location = URL;
    }
}