function isInt(passedVal) { // check if the string is an integer
if (passedVal == "") {
return false;
}
for (i=0; i<passedVal.length; i++) {
//  if (passedVal.charAt(i) != "-") { // allow the dash (e.g. 95762-8122);
if (passedVal.charAt(i) < "0") {
return false;
}
if (passedVal.charAt(i) > "9") {
return false;
}
//  }
}
return true;
}
function goto_login(form_name) { // ct_main.htm
var the_form = document[form_name];
the_form.clicType.value = "ShowLogin";
var baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_login.pl?";
submit_form(baseUrl, form_name);
} // end function goto_login
function goto_agnt_login(form_name) { // ct_main.htm
var the_form = document[form_name];
the_form.clicType.value = "agentLogin";
var baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_login.pl?";
submit_form(baseUrl, form_name);
} // end function goto_login
function goto_signup(form_name) { // ct_main.htm
var the_form = document[form_name];
the_form.clicType.value = "showSignup";
var baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_signup.pl?";
submit_form(baseUrl, form_name);
} // end function goto_signup
function go_accmail(form_name) { // from login to account mgr page
//alert("DEBUG -- uAlias=".uAlias);
var the_form = document[form_name];
the_form.clicType.value = "showAccForward";
var baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_signup.pl?";
submit_form(baseUrl, form_name);
} // end function goto_signup
function go_accmgr(form_name) { // from login to account mgr page
//alert("DEBUG -- uAlias=".uAlias);
var the_form = document[form_name];
if ((the_form.uAlias.value == "Guest") ||
(the_form.uAlias.value == "")) {
alert("Please sign in to your account.");
} else {
the_form.clicType.value = "showAccMgr";
var baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_signup.pl?";
submit_form(baseUrl, form_name);
}
} // end function goto_signup
function reset_pword(form_name) { // ct_accmgr.htm
var the_form = document[form_name];
if (the_form.uAlias.value == "Guest") {
alert("Please sign in to your account.");
} else {
var uPswd = the_form.uPswrd.value;
var uPswdCnfm = the_form.uPswrdCnfm.value;
var oldPswrd = the_form.oldPswrd.value;
if (oldPswrd == "") {
alert("Please enter your password.");
the_form.oldPswrd.focus();
} else if (uPswd == "") {
alert("Please enter your password.");
the_form.uPswrd.focus();
} else if (uPswd != uPswdCnfm) {
alert("Re-typed password does not match your password. Try it again.");
the_form.uPswrd.select();
} else {
the_form.clicType.value = "changePWD";
var baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_signup.pl?";
submit_form(baseUrl, form_name);
}
}
}
function reset_email(form_name) { // ct_accmgr.htm
var the_form = document[form_name];
if (the_form.uAlias.value == "Guest") {
alert("Please sign in to your account.");
} else {
var uPswd = the_form.psword.value;
var newEmail = the_form.newEmail.value;
if (oldPsnewEmailwrd == the_form.uAlias.value) {
alert("The new email is the same as the existing one.");
the_form.newEmail.focus();
} else if (uPswd == "") {
alert("Please enter your password.");
the_form.psword.focus();
} else {
the_form.clicType.value = "changeEML";
var baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_signup.pl?";
submit_form(baseUrl, form_name);
}
}
}
function updt_usr_info(form_name) { // ct_main.htm
var the_form = document[form_name];
var uPswd = the_form.uPword.value;
if (the_form.uAlias.value == "Guest") {
alert("Please sign in to your account.");
} else if (uPswd == "") {
alert("For your protection, please enter your password.");
the_form.uPword.focus();
} else {
the_form.clicType.value = "changeUINFO";
var baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_signup.pl?";
submit_form(baseUrl, form_name);
}
}
function resend_pword(form_name) { // ct_main.htm
var the_form = document[form_name];
if(confirm("The computer will assign you a new password. Are you sure you want to proceed?")) {
the_form.clicType.value = "resendPWD";
var baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_signup.pl?";
submit_form(baseUrl, form_name);
} else {
}
}
function logout(form_name) { // ct_main.htm
var the_form = document[form_name];
if (the_form.uAlias.value == "Guest") {
alert("You are not currently logged in.");
} else if (confirm("Unsaved information will be lost. Are you sure to log out?")) {
the_form.clicType.value = "logout";
var baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_login.pl?";
submit_form(baseUrl, form_name);
}
} // end function logout
function goto_main(form_name) {
var the_form = document[form_name];
the_form.clicType.value = "gotoMain";
var baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_adddest.pl?";
submit_form(baseUrl, form_name);
} // end function goto_main(form_name)
function hotel_updated(form_name) {
var the_form = document[form_name];
if ((the_form.checkinDate.value != "")  &&
(the_form.daysToStay.value != "")) {
if (isInt(the_form.daysToStay.value)) {
if (the_form.daysToStay.value < 1) {
alert("Please enter the number of days you plan to stay.");
the_form.hotel_id.selectedIndex = 0;
the_form.daysToStay.focus();
} else {
if (the_form.hotel_id.value > -1)  {
the_form.clicType.value = "hotel_updated";
var baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_showpkg.pl?";
submit_form(baseUrl, form_name);
}  else  {
the_form.hotel_id.selectedIndex = 0;
the_form.daysToStay.focus();
alert("Please select a hotel.");
}
}
} else {
alert("Please enter the number of days you plan to stay.");
the_form.hotel_id.selectedIndex = 0;
the_form.daysToStay.focus();
}
} else {
alert("Please enter your arrival date and the number of days you plan to stay.");
the_form.hotel_id.selectedIndex = 0;
the_form.checkinDate.focus();
}
} // end function goto_dest_cstm(form_name)
function goto_rvw_dest(form_name, destId) {
var the_form = document[form_name];
the_form.clicType.value = "pkg_revw";
the_form.destId.value = destId;
var baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_showpkg.pl?";
submit_form(baseUrl, form_name);
} // end function goto_dest_cstm(form_name)
function startover(form_name) {
var the_form = document[form_name];
the_form.clicType.value = "startover";
var baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_adddest.pl?";
submit_form(baseUrl, form_name);
} // end function goto_neworder(form_name)
function start_ini(form_name) { // same as startover, except has a def date
var the_form = document[form_name];
the_form.clicType.value = "startover";
the_form.def_arr_date.value = getNextWeekDate(); // default arrival date to one week past current day
var baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_adddest.pl?";
submit_form(baseUrl, form_name);
} // end function goto_neworder(form_name)
function restart (form_name) {
if (confirm("All your itinerary will be cleared. Are you sure you want to start over?")) {
var the_form = document[form_name];
the_form.clicType.value = "startover";
var baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_adddest.pl?";
submit_form(baseUrl, form_name);
}
} // end function goto_neworder(form_name)
function new_order(form_name) {
var the_form = document[form_name];
the_form.clicType.value = "new_order";
var baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_adddest.pl?";
submit_form(baseUrl, form_name);
} // end function new_order(form_name)
function buildPerlUrl(baseUrl, form_name) {
// canNOT do for (var objProp in the_form) because
// more properties than just the form inputs.
// e.g. 'onmouseover' is considered a property
var the_form = document[form_name];
var the_formLength = the_form.elements.length;
for(var fidx=0;fidx<the_formLength;fidx++) {
switch(the_form.elements[fidx].type) {
case "text":
baseUrl += the_form.elements[fidx].name + "=" + the_form.elements[fidx].value + "&";
break;
case "select-one":
baseUrl += the_form.elements[fidx].name + "=" + the_form.elements[fidx].options[the_form.elements[fidx].selectedIndex].value + "&";
break;
case "radio":
if (the_form.elements[fidx].checked) {
baseUrl += the_form.elements[fidx].name + "=" + the_form.elements[fidx].value + "&";
}
break;
default:
baseUrl += the_form.elements[fidx].name + "=" + the_form.elements[fidx].value + "&";
break;
}
} // end for(var fidx=0;fidx<the_formLength;fidx++)
var perlUrl = baseUrl.substr(0,(baseUrl.length - 1));
return perlUrl;
}
function submit_form(baseUrl, form_name) {
var perlUrl = buildPerlUrl(baseUrl, form_name);
// DEBUG
//  alert("ct_main.js, perlUrl:"+perlUrl);
readSvrData(perlUrl);
} // end function submit_form(form_name)
// send ussage alert message (or user's usage errors)
function error_alert() {
if (document.main_form != undefined) {
var errorFlag = document.main_form.cgiErr.value;
if (errorFlag == "yes") {
alert(document.main_form.cgiMsg.value);
}
}
} // end function error_alert()
function get_pkg(form_name) { // ct_dest_pkg.htm
var the_form = document[form_name];
the_form.clicType.value = "pkg_details";
var baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_showpkg.pl?";
submit_form(baseUrl, form_name);
} // end function get_pkg(pkgId, form_name)
function faq_popup() {
var thisURL = "http://www.uniquetravel.net/info/ct_faq.htm";
newWindow = window.open(thisURL, "newWin", "toolbar=no,location=no,scrollbars=yes,resizable=yes,width=650,height=600");
newWindow.focus();
} // end function faq_popup()
function moredeals_popup() {
alert("To be implemented.");
} // end function moredeals_popup()
function select_hotdeal(form_name, cty_ptr, num_ppl, duration) {
// check to make sure user filled in a date
var the_form = document[form_name];
if (!(the_form.arrivalDay.value)) {
alert("Please select an arrival date.");
} else {
the_form.clicType.value = "select_hotdeal";
the_form.hotdeal_cty_ptr.value = cty_ptr;
the_form.hotdeal_num_ppl.value = num_ppl;
the_form.hotdeal_num_day.value = duration;
var baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_showpkg.pl?";
submit_form(baseUrl, form_name);
}
} // end function select_hotdeal()
function select_sidedeal(form_name, cty_ptr, num_ppl, duration) {
// check to make sure user filled in a date
var the_form = document[form_name];
if (document.main_form) {
if (document.main_form.uAlias) {
the_form.uAlias.value = document.main_form.uAlias.value;
the_form.uPtr.value = document.main_form.uPtr.value;
}
}
//alert("ct_main.js - tDate=test test");
var nextDate = getNextWeekDate();
//alert("ct_main.js - nextDate="+nextDate);
the_form.arrivalDay.value = nextDate;
the_form.clicType.value = "select_hotdeal";
the_form.hotdeal_cty_ptr.value = cty_ptr;
the_form.hotdeal_num_ppl.value = num_ppl;
the_form.hotdeal_num_day.value = duration;
var baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_showpkg.pl?";
submit_form(baseUrl, form_name);
}
function add_destination(form_name) {
var the_form = document[form_name];
if (isInt(the_form.no_adults.value)) {
} else {
alert("Please enter the number of adults in your group.");
the_form.no_adults.focus();
return;
}
if (isInt(the_form.no_kids.value)) {
} else {
alert("Please enter the number of children in your group.");
the_form.no_kids.focus();
return;
}
if (!(the_form.arrivalDay.value)) {
alert("Please select an arrival date.");
} else if (!(the_form.no_adults.value)) {
alert("Please fill in the number of adults.");
} else if (!(the_form.destinationSelect.value)) {
alert("Please select a destination.");
} else {
the_form.clicType.value = "add_destination";
var baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_main.pl?";
submit_form(baseUrl, form_name);
}
} // end function add_destination()
function buyIt(form_name) {
var the_form = document[form_name];
the_form.clicType.value = "buy_pal";
var baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_pay.pl?";
submit_form(baseUrl, form_name);
}
function save_settings(form_name) {
var the_form = document[form_name];
var uPswd = the_form.uPswrd.value;
if (uPswd == "") {
alert("For your protection, please enter your password.");
} else {
if (confirm("This will save and overwrite your existing record.  Are you sure you want to proceed?")) {
the_form.clicType.value = "save_rec";
var baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_recd.pl?";
submit_form(baseUrl, form_name);
}
}
} // end function save_settings(form_name)
function delete_dest(form_name) {
var the_form = document[form_name];
if (the_form.uAlias.value == "Guest") {
alert("Please sign in with your email address.");
} else {
if (confirm("Are you sure you want to remove the destination from your itinerary?")) {
the_form.clicType.value = "rm_dest";
var baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_recd.pl?";
submit_form(baseUrl, form_name);
}
}
} // end function delete_dest(form_name)
function new_hotel(form_name, new_hotel_idx) {
var the_form = document[form_name];
the_form.clicType.value = "hotel_list";
the_form.opcode.value = "add";
the_form.hotel_id.value = 1;
the_form.hotel_idx.value = new_hotel_idx;
var baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_main.pl?";
submit_form(baseUrl, form_name);
} // end function new_hotel()
function modify_hotel(form_name, hotel_id, hotel_idx, room_type) {
var the_form = document[form_name];
the_form.clicType.value = "hotel_list";
the_form.opcode.value = "modify";
//  the_form.daysToStay.value = hotel_ni; // number of nights in this hotel
the_form.hotel_id.value = hotel_id;
the_form.hotel_idx.value = hotel_idx;
the_form.room_type.value = room_type;
var baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_main.pl?";
submit_form(baseUrl, form_name);
} // end function add_destination()
// update the optional features in a desination tour
function modify_srvc(form_name, param_id, param_val) {
var the_form = document[form_name];
if ((the_form.arrivalDay.value != "")  &&
(the_form.n_days.value != "")) {
if (isInt(the_form.no_adults.value)) {
} else {
alert("Please enter the number of adults in your group.");
the_form.no_adults.focus();
return;
}
if (isInt(the_form.no_children.value)) {
} else {
alert("Please enter the number of children in your group.");
the_form.no_children.focus();
return;
}
if (isInt(the_form.n_days.value)) {
if (the_form.n_days.value < 1) {
alert("Please enter the number of days you plan to stay.");
the_form.n_days.focus();
} else {
the_form.clicType.value = "updatePkg";
the_form[param_id].value = param_val;
var baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_showpkg.pl?";
if ( the_form.thisPage.value == "ct_rvw_trip") {
baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_recd.pl?";
}
submit_form(baseUrl, form_name);
}
} else {
alert("Please enter the number of days you plan to stay.");
the_form.hotel_id.selectedIndex = 0;
the_form.n_days.focus();
}
} else {
alert("Please enter your arrival date and the number of days you plan to stay.");
the_form.hotel_id.selectedIndex = 0;
the_form.checkinDate.focus();
}
}
// The function below is for insurance flag only, but can be expanded
function modify_ins(form_name, param_id, param_val) {
var the_form = document[form_name];
the_form.clicType.value = "updatePkg";
the_form[param_id].value = param_val;
var baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_showpkg.pl?";
submit_form(baseUrl, form_name);
}
// The function below is for insurance flag only, but can be expanded
function modify_ins_rvwtrip(form_name, param_id, param_val) {
var the_form = document[form_name];
the_form.clicType.value = "updatePkg";
the_form[param_id].value = param_val;
var baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_recd.pl?";
submit_form(baseUrl, form_name);
}
function delete_hotel(form_name, hotel_id, hotel_idx) {
var the_form = document[form_name];
the_form.clicType.value = "delete_hotel";
the_form.hotel_id.value = hotel_id;
the_form.hotel_idx.value = hotel_idx;
var baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_main.pl?";
submit_form(baseUrl, form_name);
} // end function add_destination()
//function view_activities() {
//  alert("What variables are needed to be inputted?");
//} // end function view_activities()
function submit_dest_cstm(form_name) {
var the_form = document[form_name];
if ((the_form.arrivalDay.value != "")  &&
(the_form.n_days.value != "")) {
if (isInt(the_form.no_adults.value)) {
} else {
alert("Please enter the number of adults in your group.");
the_form.no_adults.focus();
return;
}
if (isInt(the_form.no_children.value)) {
} else {
alert("Please enter the number of children in your group.");
the_form.no_children.focus();
return;
}
if ((isInt(the_form.n_days.value)) && (isInt(the_form.n_night.value))) {
var myDays = the_form.n_days.value;
var myNite = the_form.n_night.value;
var myStay = parseInt(myNite) + 1;
if (the_form.n_days.value < 1) {
alert("Please enter the number of days you plan to stay.");
the_form.n_days.focus();
} else if (myDays != myStay) {
//        alert("The days of tour must be one more than your hotel stay.");
alert("You have a tour of "+myDays+" days, but saty "+myNite+" night(s) of hotel(s). Please adjust.");
the_form.n_days.focus();
} else {
if (the_form.uAlias.value == "Guest") {
alert("Please sign in to your account.");
} else {
the_form.clicType.value = "add_dest";
var baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_recd.pl?";
submit_form(baseUrl, form_name);
}
}
} else {
alert("Please double check the number of days you plan to stay and your hotel reservation.");
the_form.hotel_id.selectedIndex = 0;
the_form.n_days.focus();
}
} else {
alert("Please enter your arrival date and the number of days you plan to stay.");
the_form.hotel_id.selectedIndex = 0;
the_form.checkinDate.focus();
}
} // end function submit_dest_cstm()
function user_signup(form_name) {
var the_form = document[form_name];
var uPswd = the_form.uPswrd.value;
var uPswdCnfm = the_form.uPswrdCnfm.value;
var uEmail = the_form.uEmail.value;
if (uPswd != uPswdCnfm) {
alert("Re-entered password does not match your password. Try it again.");
the_form.uPswrdCnfm.select();
} else if (uEmail == "") {
alert("Please enter your email address.");
the_form.uEmail.focus();
} else {
the_form.clicType.value = "signMeUp";
var baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_signup.pl?";
submit_form(baseUrl, form_name);
}
} // end function user_signup(form_name)
// user login. Load existing Itinerary
function view_rec(form_name) {
var the_form = document[form_name];
if ((the_form.uAlias.value == "Guest") ||
(the_form.uAlias.value == "")) {
alert("Please sign in.");
} else {
var the_form = document[form_name];
the_form.clicType.value = "view_rec";
var baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_recd.pl?";
submit_form(baseUrl, form_name);
}
}
// user login. Load existing Itinerary
function u_login_back(form_name) {
var the_form = document[form_name];
the_form.clicType.value = "login_back";
var baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_login.pl?";
submit_form(baseUrl, form_name);
}
// user login. create a new Itinerary
function u_login_new(form_name) {
var the_form = document[form_name];
the_form.clicType.value = "login_new";
var baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_adddest.pl?";
submit_form(baseUrl, form_name);
}
function openHotelWin(form_name) {
var the_form = document[form_name];
if (the_form.hotel_id.options[the_form.hotel_id.selectedIndex].value != -1) { // the 'select a hotel' field value is '-1'
var baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_hprice.pl?";
the_form.clicType.value = "hotel_cost";
var perlUrl = buildPerlUrl(baseUrl, form_name);
newWindow = window.open(perlUrl, "newWin", "toolbar=no,location=no,scrollbars=yes,resizable=yes,width=410,height=300");
newWindow.focus();
} else {
alert("Please select a hotel.");
the_form.hotel_id.focus();
}
}
function changeHotelName(form_name, hotel_id) {
var the_form = document[form_name];
if ((the_form.checkinDate.value != "")  &&
(the_form.daysToStay.value != "")) {
if (isInt(the_form.daysToStay.value)) {
if (the_form.daysToStay.value < 1) {
alert("Please enter the number of nights you plan to stay at the hotel.");
the_form.hotel_id.selectedIndex = 0;
the_form.daysToStay.focus();
} else {
the_form.clicType.value = "hotel_list";
the_form.hotel_id.value = hotel_id;
the_form.room_type.value = 1; //default to the first room type
var baseUrl = "http://www.uniquetravel.net/cgi-bin/ct_main.pl?";
submit_form(baseUrl, form_name);
}
} else {
alert("Please enter the number of days you plan to stay.");
the_form.hotel_id.selectedIndex = 0;
the_form.daysToStay.focus();
}
} else {
alert("Please enter your arrival date and the number of days you plan to stay.");
the_form.hotel_id.selectedIndex = 0;
the_form.checkinDate.focus();
}
}
function popup_page(hotel_id) {
newWindow = window.open(hotel_id, "newWin", "toolbar=no,location=no,scrollbars=yes,resizable=yes,width=700,height=400");
newWindow.focus();
}
function tourCheckBox(flag) { // ct_dest_cstm.htm
if (flag == "yes") { // currently yes, so make it no
modify_srvc('main_form', 'tourguide', 'no');
} else {
modify_srvc('main_form', 'tourguide', 'yes');
}
}
function attrCheckBox(flag) { // ct_dest_cstm.htm
if (flag == "yes") { // currently yes, so make it no
modify_srvc('main_form', 'attr_sel', 'no');
} else {
modify_srvc('main_form', 'attr_sel', 'yes');
}
}
function insCheckBoxRvw(flag) { // ct_rvw_trip.htm
if (flag == "yes") { // currently yes, so make it no
modify_ins_rvwtrip('main_form', 'updateIns', 'no');
} else {
modify_ins_rvwtrip('main_form', 'updateIns', 'yes');
}
}
function insCheckBox(flag) { // ct_dest_cstm.htm
if (flag == "yes") { // currently yes, so make it no
modify_srvc('main_form', 'updateIns', 'no');
} else {
modify_srvc('main_form', 'updateIns', 'yes');
}
}
function getTodayDate() {
var currentTime = new Date();
var currMonth = currentTime.getMonth() + 1; // getMonth returns 0-11, Jan-Dec
if (currMonth < 10) {
currMonth = "0"+currMonth;
}
var currDate = currentTime.getDate();
var currYear = currentTime.getYear();
//alert(""+currMonth+"-"+currDate+"-"+currYear+"");
return(""+currMonth+"-"+currDate+"-"+currYear+"");
}
function getNextWeekDate() {
var currentTime = new Date();
// getTime() returns the number of milliseconds since January 1, 1970, 00:00:00 GMT
var dateSevenAfter = new Date(currentTime.getTime() + (7 * 86400000));
var theMonth = dateSevenAfter.getMonth() + 1; // getMonth returns 0-11, Jan-Dec
if (theMonth < 10) {
theMonth = "0"+theMonth;
}
var theDate = dateSevenAfter.getDate();
var theYear = dateSevenAfter.getFullYear();
//alert(""+theMonth+"-"+theDate+"-"+theYear+"");
return(""+theMonth+"-"+theDate+"-"+theYear+"");
}
function redirectToPayPal(form_name) {
document[form_name].submit();
}
function loadingFunction() {
if (document.main_form) {
if (document.main_form.thisPage) {
if (document.main_form.thisPage.value == "ut_redirect") {
redirectToPayPal('main_form');
}
}
}
}

