// #################################################
// NOTE: All Functions included in this file have a prefix of "cs_"
// #################################################
var CONST_CS_STR = "CargoSmart";
var CONST_CS_STR_ALL_LOW_CASE = "cargosmart";
var CONST_WIN_STR = "win";
var CONST_HELP_URL = "http://www.cargosmart.com/onlinehelp/CustomerHelp/FlashHelp/CargoSmartOnlineHelp.htm";
var CONST_CF_HELP_URL = "http://www.cargosmart.com/onlinehelp/CarrierHelp/FlashHelp/CargoSmartOnlineHelp.htm";

//window handle for pdf display window 
var pdfWindow;
//window handle for the payment instructions/batch window
var piWindow;
//window handle for the print/batch window
var bpWindow;
var previewWindow;
var partnership_instance = 0;
var user_instance = 0;
var abackstroke = 47;
var bkg_instance = 0;
var pf_sc_instance = 0;
var pr_sc_instance = 0;
var rpt_templ_instance = 0;
var si_instance = 0;
var si_templ_instance = 0;
var si_draft_instance = 0;
var view_pa_instance = 0;
var view_inv_instance = 0;
var screen_ht = screen.availHeight;
var screen_wd = screen.availWidth;
var screen_left = 0;
var screen_top = 10;
var last_mod_date_tou = " ";
var last_mod_date_pss = ".";
var last_mod_ver_pss = "";
var last_mod_date_tou_format = "17 February 2008";
var last_mod_date_pss_format = "17 February 2008";
var legal_year = "2000 - 2009";
CS2_TOUURL = "http://www.cargosmart.com/en/company/tou/tou.htm";
CS2_COPYURL = "http://www.cargosmart.com/en/company/tou/tou.htm#cip";
CS2_PSSURL = "http://www.cargosmart.com/en/company/tou/pss.htm";
FULL = "toolbar,directories,resizable,status,scrollbars,menubar,location,";
NONE = "scrollbars,resizable,status,";
MENUONLY = "menubar,scrollbars,resizable,status,";
ALL = "";
serverurl = "http://www.cargosmart.com/";
contenturl = "http://www.cargosmart.com/";
publicurl = "http://www.cargosmart.com/";
appurl = "http://app2.cargosmart.com/cs/";
appservlet = "http://app2.cargosmart.com/cs/servlet/icss";
appSSLservlet = "https://app1.cargosmart.com/cmf/servlet/icss";
appMCIservlet = "https://app3.cargosmart.com/mci/servlet/icss";
cnserverurl = "http://www.cargosmart.cn/";
appdomain = "; domain=.cargosmart.com";
TOUURL = contenturl + "about/terms_of_use.htm";
COPYURL = contenturl + "about/terms_of_use.htm#Section5";
PSSURL = contenturl + "about/privacy_policy.htm";
EXITURL = contenturl + "exit.htm";
var infozone_serverurl = "http://carriers.cargosmart.com/";
var_submit_win = "navigation.submit_win";
var_work_id = "navigation.workId";
var_action = "navigation.action";
var_task_id = "navigation.taskId";
var_cache_id = "navigation.cacheId";
var_new_task = "navigation.newTask";
var_ssl = "navigation.ssl";
var_get_page = "getPage";
var_proceed = true;
/**
 * loads the batch print page, storing the windowHandle bpWindow,
 * and provides confirmation box if window already exists
 */
function cs_bpClick(newWin, windowName, windowType, url, form, method, para) {
    windownames = cs_getWindowName(windowName);
    // make this window smaller to resolve pop-over problem
    var w_ht = Math.round(0.7 * screen_ht);
    var w_wd = Math.round(0.7 * screen_wd);
    var w_left = (screen_wd - w_wd) - 20;
    windowType += "left=" + w_left + ",top=" + screen_top + ",screenX=" + w_left + ",screenY=" + screen_top + ",";
    windowType += "height=" + w_ht + ",width=" + w_wd;
    form.action = url;
    form.method = method;
    if (form.elements[var_submit_win] != null) {
        form.elements[var_submit_win].value = escape(windownames);
    }
    if (form.elements[var_ssl] != null) {
        form.elements[var_ssl].value = cs_isSSL(form.action);
    }
    if (newWin == true) {
        if (pdfWindow && !pdfWindow.closed) {
            alert("Please close the pdf file before loading new pdf");
            return;
        } else {
            if (bpWindow && !bpWindow.closed) {
                var confirmMsg = "Are you sure that you want to discard your existing batch print selections?";
                var overwriteSettings = confirm(confirmMsg);
                if (!overwriteSettings) {
                    return;
                } else {
                    bpWindow.close();
                }
            }
        }
        if ((bpWindow = windowManagement_openWindow("cs.htm", windowName, windowType)) == null) {
            return;
        }
        form.target = windowName;
    } else {
        form.target = "_self";
    }
    form.submit();
}

// This function is used mainly in BKG JSPs when it is a new bkg request, not from shptdtl, and the passed serial ref number is empty.
function cs_setSerialNo(from) {
    wn = self.name;
    sn = from + wn.substring(7);
    return sn;
}
function cs_turnOn(imageName) {
    if (document.images) {
        document[imageName].src = eval(imageName + "on.src");
    }
}
function cs_turnOff(imageName) {
    if (document.images) {
        document[imageName].src = eval(imageName + "off.src");
    }
}
function cs_spacer(w, imagepath) {
    document.writeln("<img src='" + imagepath + "spacer.gif' width='" + w + "' HEIGHT='1'>");
}
function cs_popup(url) {
    popupWin = window.open(url + "?getPage=popup.jsp" + "&" + var_ssl + "=" + cs_isSSL(url), "popup", "width=400,height=240,left=300,top=300");
}
function cs_popupPage(url, winsize, winname, winparms) {
    if (winsize == "S") {
        scalar = 0.33;
    } else {
        if (winsize == "M") {
            scalar = 0.5;
        } else {
            if (winsize == "L") {
                scalar = 0.75;
            } else {
                scalar = 0.9;
            }
        }
    }
    w_ht = Math.round(scalar * screen_ht);
    w_wd = Math.round(scalar * screen_wd);
    w_left = (screen_wd - w_wd) - 20;
    winparms += "left=" + w_left + ",top=" + screen_top + ",screenX=" + w_left + ",screenY=" + screen_top + ",";
    winparms += "height=" + w_ht + ",width=" + w_wd;
    if (window.noncsWin) {
        if (!noncsWin.closed) {
            noncsWin.close();
        }
    }
    noncsWin = windowManagement_openWindow(url, winname, winparms);
    return;
}
function cs_popupTOU() {
    cs_popupPage(TOUURL, "L", "cslegal", NONE);
}
function cs_popupCopyRight() {
    cs_popupPage(COPYURL, "L", "cslegal", NONE);
}
function cs_popupPSS() {
    cs_popupPage(PSSURL, "L", "cslegal", NONE);
}
function cs_popupExit(url) {
    w_top = Math.round((screen_ht - 300) * 0.5);
    w_left = Math.round((screen_wd - 460) * 0.5);
    winparms = "width=460,height=200,";
    winparms += "left=" + w_left + ",top=" + w_top;
    exitWin = window.open(contenturl + "exit.htm", "popup", winparms);
    cs_popupPage(url, "X", "noncs", FULL);
    exitWin.focus();
}
function cs_openPage(page) {
    if (page == "sign_in") {
        page = "hp_public";
    } else {
        if (page == "register") {
            page = "pf_register";
        } else {
            if (page == "forget_pwd") {
                page = "pf_forget_pwd";
            } else {
                if (page == "track_cargo") {
                    page = "ct_criteria_p";
                } else {
                    if (page == "contact") {
                        page = "mi_contact_us_p";
                    } else {
                        page = "hp_" + page;
                    }
                }
            }
        }
    }
    document.frmSubmit.elements["getPage"].value = page + ".jsp";
    document.frmSubmit.elements[var_ssl].value = cs_isSSL(location.protocol);
}
function cs_getSignOffPage() {
    document.frm_sign_off.elements[var_work_id].value = "GetSignOffWork";
    document.frm_sign_off.elements[var_action].value = "forward";
    document.frm_sign_off.elements[var_task_id].value = "GetSignOffTask";
    document.frm_sign_off.elements[var_cache_id].value = "sys_sign_off";
    document.frm_sign_off.elements[var_new_task].value = true;
    document.frm_sign_off.elements[var_get_page].value = "sys_sign_off.jsp";
    document.frm_sign_off.target = "cargosmart";
    document.frm_sign_off.method = "post";
    document.frm_sign_off.submit();
}
function cs_cfgetSignOffPage() {
    document.frm_sign_off.elements[var_work_id].value = "GetSignOffWork";
    document.frm_sign_off.elements[var_action].value = "forward";
    document.frm_sign_off.elements[var_task_id].value = "GetSignOffTask";
    document.frm_sign_off.elements[var_cache_id].value = "sys_sign_off";
    document.frm_sign_off.elements[var_new_task].value = true;
    document.frm_sign_off.elements[var_get_page].value = "cf_sys_sign_off.jsp";
    document.frm_sign_off.target = "csc_cargosmart";
    document.frm_sign_off.method = "post";
    document.frm_sign_off.submit();
}
function cs_getHomePage() {
    document.frm_header_footer.elements[var_work_id].value = "GetHomePageWork";
    document.frm_header_footer.elements[var_action].value = "forward";
    document.frm_header_footer.elements[var_task_id].value = "GetHomePageTask";
    document.frm_header_footer.elements[var_cache_id].value = "footer_all";
    document.frm_header_footer.elements[var_new_task].value = true;
    return true;
}
function cs_getIUHomePage() {
    document.i_frm_header_footer.elements[var_work_id].value = "IUGetHomePageWork";
    document.i_frm_header_footer.elements[var_action].value = "forward";
    document.i_frm_header_footer.elements[var_task_id].value = "IUGetHomePageTask";
    document.i_frm_header_footer.elements[var_cache_id].value = "iu_header_primary";
    document.i_frm_header_footer.elements[var_new_task].value = true;
    return true;
}
function cs_getContactUs() {
    document.frm_header_footer.elements["hdr.ref_page"].value = document.title;
    document.frm_header_footer.elements[var_work_id].value = "ContactUsWork";
    document.frm_header_footer.elements[var_action].value = "forward";
    document.frm_header_footer.elements[var_task_id].value = "ContactUsTask";
    document.frm_header_footer.elements[var_new_task].value = true;
    document.frm_header_footer.elements[var_cache_id].value = "mi_help";
    return true;
}
function cs_getContactUsForChgPwd() {
    document.frm_header_footer.elements["hdr.ref_page"].value = document.title;
    document.frm_header_footer.elements[var_work_id].value = "ContactUsWork";
    document.frm_header_footer.elements[var_action].value = "forward";
    document.frm_header_footer.elements[var_task_id].value = "ContactUsTask";
    document.frm_header_footer.elements[var_cache_id].value = "footer_changepassword";
    document.frm_header_footer.elements[var_new_task].value = true;
    return true;
}
function cs_getContactUsForAll() {
    document.frm_header_footer.elements["hdr.ref_page"].value = document.title;
    document.frm_header_footer.elements[var_work_id].value = "ContactUsWork";
    document.frm_header_footer.elements[var_action].value = "forward";
    document.frm_header_footer.elements[var_task_id].value = "ContactUsTask";
    document.frm_header_footer.elements[var_cache_id].value = "footer_all";
    document.frm_header_footer.elements[var_new_task].value = true;
    return true;
}
function cs_getPublicContactUs() {
    document.frm_header_footer.elements["hdr.ref_page"].value = document.title;
    document.frm_header_footer.elements[var_work_id].value = "ContactUsPublicWork";
    document.frm_header_footer.elements[var_action].value = "forward";
    document.frm_header_footer.elements[var_task_id].value = "ContactUsPublicTask";
    document.frm_header_footer.elements[var_new_task].value = true;
    return true;
}
function cs_getHelp() {
    var astr = "getPage=mi_help.jsp&hdr.ref_page=" + document.title + "&" + var_ssl + "=" + cs_isSSL(location.protocol);
    return astr;
}
function cs_getCFHelp() {
    var astr = "getPage=mi_help.jsp&hdr.ref_page=" + document.title + "&hdr.forCarrierUser=1&" + var_ssl + "=" + cs_isSSL(location.protocol);
    return astr;
}
function cs_getIUHelp() {
    var astr = "getPage=mi_help.jsp&hdr.ref_page=" + document.title + "&" + var_ssl + "=" + cs_isSSL(location.protocol);
    return astr;
}
function cs_getCarrierContactUs() {
    document.frm_header_footer.elements[var_work_id].value = "CarrierContactUsWork";
    document.frm_header_footer.elements[var_action].value = "forward";
    document.frm_header_footer.elements[var_task_id].value = "CarrierContactUsTask";
    document.frm_header_footer.elements[var_new_task].value = true;
    document.frm_header_footer.elements[var_cache_id].value = "cf_contact_us";
    return true;
}
function cs_isSSL(url) {
    if (url.indexOf("http") == -1) {
        return cs_isSSL(location.protocol);
    }
    if (url.indexOf("https") == -1) {
        return false;
    } else {
        return true;
    }
}
function cs_submitClickSmallWinCenter(newWin, windowName, winsize, url, form, method, para) {
    if (var_proceed) {
        var_proceed = false;
        windownames = cs_getWindowName(windowName);
        winsize = winsize.toUpperCase();
        if (winsize == "S") {
            scalar = 0.33;
        } else {
            if (winsize == "M") {
                scalar = 0.5;
            } else {
                if (winsize == "L") {
                    scalar = 0.75;
                } else {
                    scalar = 0.9;
                }
            }
        }
        w_ht = Math.round(scalar * screen_ht);
        w_wd = Math.round(scalar * screen_wd);
        w_left = Math.round((screen_wd - w_wd) * 0.5);
        w_top = Math.round((screen_ht - w_ht) * 0.5);
        windowparms = "resizable=yes,status=yes,scrollbars=yes,";
        windowparms += "left=" + w_left + ",top=" + w_top + ",screenX=" + w_left + ",screenY=" + w_top + ",";
        windowparms += "height=" + w_ht + ",width=" + w_wd;
        if (method == "get") {
            para = var_submit_win + "=" + escape(windownames) + "&" + para + "&" + var_ssl + "=" + cs_isSSL(url);
            if (newWin == true) {
                var_proceed = false;
                if ((newWindow = windowManagement_openWindow(url + "?" + para, windowName, windowparms)) == null) {
                    var_proceed = true;
                    return;
                }
                var_proceed = true;
            } else {
                window.location.href = url + "?" + para;
            }
        } else {
            if (method == "post") {
                form.method = method;
                if (form.elements[var_submit_win] != null) {
                    form.elements[var_submit_win].value = escape(windownames);
                }
                if (form.elements[var_ssl] != null) {
                    form.elements[var_ssl].value = cs_isSSL(form.action);
                }
                if (newWin == true) {
                    var_proceed = false;
                    if (windowName == "preview") {
                        if ((previewWindow = windowManagement_openWindow("cs.htm", windowName, windowparms)) == null) {
                            var_proceed = true;
                            return;
                        }
                    } else {
                        if ((newWindow = windowManagement_openWindow("cs.htm", windowName, windowparms)) == null) {
                            var_proceed = true;
                            return;
                        }
                    }
                    form.target = windowName;
                    form.submit();
                    var_proceed = true;
                } else {
                    form.target = "_self";
                    form.submit();
                }
            } else {
                return;
            }
        }
    } else {
        alert("Please wait while processing...");
    }
}

// The following function is used for CitiConnect related window opening only
function cs_submitClickCitiConnect(newWin, windowName, winsize, url, form, method, para) {
    if (var_proceed) {
        var_proceed = false;
        windownames = cs_getWindowName(windowName);
        winsize = winsize.toUpperCase();
        if (winsize == "S") {
            scalar = 0.33;
        } else {
            if (winsize == "M") {
                scalar = 0.5;
            } else {
                if (winsize == "L") {
                    scalar = 0.75;
                } else {
                    scalar = 0.9;
                }
            }
        }
        w_ht = 600;
        w_wd = 775;
        w_left = Math.round((screen_wd - w_wd) * 0.5);
        w_top = Math.round((screen_ht - w_ht) * 0.5);
        windowparms = "width=775,height=600,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=yes,directories=no,status=yes,";
        windowparms += "left=" + w_left + ",top=" + w_top + ",screenX=" + w_left + ",screenY=" + w_top + ",";
        if (method == "get") {
            para = var_submit_win + "=" + escape(windownames) + "&" + para + "&" + var_ssl + "=" + cs_isSSL(url);
            if (newWin == true) {
                var_proceed = false;
                if ((newWindow = windowManagement_openWindow(url + "?" + para, windowName, windowparms)) == null) {
                    var_proceed = true;
                    return;
                }
                var_proceed = true;
            } else {
                window.location.href = url + "?" + para;
            }
        } else {
            if (method == "post") {
                form.method = method;
                if (form.elements[var_submit_win] != null) {
                    form.elements[var_submit_win].value = escape(windownames);
                }
                if (form.elements[var_ssl] != null) {
                    form.elements[var_ssl].value = cs_isSSL(form.action);
                }
                if (newWin == true) {
                    var_proceed = false;
                    form.target = windowName;
                    if (windowName == "preview") {
                        if ((previewWindow = windowManagement_openWindow("cs.htm", windowName, windowparms)) == null) {
                            var_proceed = true;
                            return;
                        }
                    } else {
                        if ((newWindow = windowManagement_openWindow("cs.htm", windowName, windowparms)) == null) {
                            var_proceed = true;
                            return;
                        }
                    }
                    form.submit();
                    var_proceed = true;
                } else {
                    form.target = "_self";
                    form.submit();
                }
            } else {
                return;
            }
        }
    } else {
        alert("Please wait while processing...");
    }
}
function cs_submitClickSmallWin(newWin, windowName, winsize, url, form, method, para) {
    if (var_proceed) {
        var_proceed = false;
        windownames = cs_getWindowName(windowName);
        winsize = winsize.toUpperCase();
        if (winsize == "S") {
            scalar = 0.33;
        } else {
            if (winsize == "M") {
                scalar = 0.5;
            } else {
                if (winsize == "L") {
                    scalar = 0.75;
                } else {
                    scalar = 0.9;
                }
            }
        }
        w_ht = Math.round(scalar * screen_ht);
        w_wd = Math.round(scalar * screen_wd);
        w_left = (screen_wd - w_wd) - 20;
        windowparms = "resizable=yes,status=yes,scrollbars=yes,";
        windowparms += "left=" + w_left + ",top=" + screen_top + ",screenX=" + w_left + ",screenY=" + screen_top + ",";
        windowparms += "height=" + w_ht + ",width=" + w_wd;
        if (method == "get") {
            para = var_submit_win + "=" + escape(windownames) + "&" + para + "&" + var_ssl + "=" + cs_isSSL(url);
            if (newWin == true) {
                var_proceed = false;
                if ((newWindow = windowManagement_openWindow(url + "?" + para, windowName, windowparms)) == null) {
                    var_proceed = true;
                    return;
                }
                var_proceed = true;
            } else {
                window.location.href = url + "?" + para;
            }
        } else {
            if (method == "post") {
                var_proceed = true;
                form.method = method;
                if (form.elements[var_submit_win] != null) {
                    form.elements[var_submit_win].value = escape(windownames);
                }
                if (form.elements[var_ssl] != null) {
                    form.elements[var_ssl].value = cs_isSSL(form.action);
                }
                if (newWin == true) {
                    var_proceed = false;
                    if ((newWindow = windowManagement_openWindow("cs.htm", windowName, windowparms)) == null) {
                        var_proceed = true;
                        return;
                    }
                    form.target = windowName;
                    form.submit();
                    var_proceed = true;
                } else {
                    form.target = "_self";
                    form.submit();
                }
            } else {
                return;
            }
        }
    } else {
        alert("Please wait while processing...");
    }
}
/**
 * Functions same as cs_submitClickSmallWin(), but it also returns the window handle of the window opened if any
 */
function cs_openChildWindow(newWin, windowName, winsize, url, form, method, para) {
    if (var_proceed) {
        var_proceed = false;
        windownames = cs_getWindowName(windowName);
        winsize = winsize.toUpperCase();
        if (winsize == "S") {
            scalar = 0.33;
        } else {
            if (winsize == "M") {
                scalar = 0.5;
            } else {
                if (winsize == "L") {
                    scalar = 0.75;
                } else {
                    scalar = 0.9;
                }
            }
        }
        w_ht = Math.round(scalar * screen_ht);
        w_wd = Math.round(scalar * screen_wd);
        w_left = Math.round((screen_wd - w_wd) * 0.5);
        w_top = Math.round((screen_ht - w_ht) * 0.5);
        windowparms = "resizable=yes,status=yes,scrollbars=yes,";
        windowparms += "left=" + w_left + ",top=" + w_top + ",screenX=" + w_left + ",screenY=" + w_top + ",";
        windowparms += "height=" + w_ht + ",width=" + w_wd;
        if (method == "get") {
            para = var_submit_win + "=" + escape(windownames) + "&" + para + "&" + var_ssl + "=" + cs_isSSL(url);
            if (newWin == true) {
                var_proceed = false;
                if ((newWindow = windowManagement_openWindow(url + "?" + para, windowName, windowparms)) == null) {
                    var_proceed = true;
                    return;
                }
                var_proceed = true;
            } else {
                window.location.href = url + "?" + para;
            }
        } else {
            if (method == "post") {
                form.method = method;
                if (form.elements[var_submit_win] != null) {
                    form.elements[var_submit_win].value = escape(windownames);
                }
                if (form.elements[var_ssl] != null) {
                    form.elements[var_ssl].value = cs_isSSL(form.action);
                }
                if (newWin == true) {
                    var_proceed = false;
                    if (windowName == "preview") {
                        if ((previewWindow = windowManagement_openWindow("cs.htm", windowName, windowparms)) == null) {
                            var_proceed = true;
                            return;
                        }
                    } else {
                        if ((newWindow = windowManagement_openWindow("cs.htm", windowName, windowparms)) == null) {
                            var_proceed = true;
                            return;
                        }
                    }
                    form.target = windowName;
                    form.submit();
                    var_proceed = true;
                } else {
                    form.target = "_self";
                    form.submit();
                }
            } else {
                return;
            }
        }
    } else {
        alert("Please wait while processing...");
    }
    if (newWindow != null && newWindow != undefined) {
        return newWindow;
    } else {
        if (previewWindow != null && previewWindow != undefined) {
            return previewWindow;
        }
    }
}
function cs_submitClickRefresh(newWin, windowName, windowType, url, form, method, para) {
    windownames = cs_getWindowName(windowName);
    var w_ht = screen_ht - 60;
    var w_wd = screen_wd - 20;
    windowType += "left=10,top=10,screenX=10,screenY=10,";
    windowType += "height=" + w_ht + ",width=" + w_wd;
    if (method == "get") {
        para = var_submit_win + "=" + escape(windownames) + "&" + para + "&" + var_ssl + "=" + cs_isSSL(url);
        if (newWin == true) {
            if ((newWindow = windowManagement_openWindow(url + "?" + para, windowName, windowType)) == null) {
                return;
            }
        } else {
            window.location.href = url + "?" + para;
        }
    } else {
        if (method == "post") {
      //form.action = url
            form.method = method;
            if (form.elements[var_submit_win] != null) {
                form.elements[var_submit_win].value = escape(windownames);
            }
            if (form.elements[var_ssl] != null) {
                form.elements[var_ssl].value = cs_isSSL(form.action);
            }
            if (newWin == true) {
                if ((newWindow = windowManagement_openWindow("cs.htm", windowName, windowType)) == null) {
                    return;
                }
                form.target = windowName;
            } else {
                form.target = "_self";
            }
            form.submit();
        } else {
            return;
        }
    }
}
function cs_submitClick(newWin, windowName, windowType, url, form, method, para) {
    if (var_proceed) {
        var_proceed = false;
        windownames = cs_getWindowName(windowName);
        var w_ht = screen_ht - 60;
        var w_wd = screen_wd - 20;
        windowType += "left=10,top=10,screenX=10,screenY=10,";
        windowType += "height=" + w_ht + ",width=" + w_wd;
        if (method == "get") {
            para = var_submit_win + "=" + escape(windownames) + "&" + para + "&" + var_ssl + "=" + cs_isSSL(url);
            if (newWin == true) {
                var_proceed = false;
                if ((newWindow = windowManagement_openWindow(url + "?" + para, windowName, windowType)) == null) {
                    var_proceed = true;
                    return;
                }
                var_proceed = true;
            } else {
                window.location.href = url + "?" + para;
            }
        } else {
            if (method == "post") {
                form.method = method;
                if (form.elements[var_submit_win] != null) {
                    form.elements[var_submit_win].value = escape(windownames);
                }
                if (form.elements[var_ssl] != null) {
                    form.elements[var_ssl].value = cs_isSSL(form.action);
                }
                if (newWin == true) {
                    var_proceed = false;
                    if ((newWindow = windowManagement_openWindow("cs.htm", windowName, windowType)) == null) {
                        var_proceed = true;
                        return;
                    }
                    form.target = windowName;
                    form.submit();
                    var_proceed = true;
                } else {
                    form.target = "_self";
                    form.submit();
                }
            } else {
                return;
            }
        }
    } else {
        alert("Please wait while processing...");
    }
}
function cs_submitSIAmenmentClick(newWin, windowName, windowType, url, form, method, para) {
    if (var_proceed) {
        var_proceed = false;
        windownames = cs_getWindowName(windowName);
        var w_ht = screen_ht - 60;
        var w_wd = screen_wd - 20;
        windowType += "left=10,top=10,screenX=10,screenY=10,";
        windowType += "height=" + w_ht + ",width=" + w_wd;
        if (method == "get") {
            para = var_submit_win + "=" + escape(windownames) + "&" + para + "&" + var_ssl + "=" + cs_isSSL(url);
            if (newWin == true) {
                var_proceed = false;
                if ((newWindow = windowManagement_openWindow(url + "?" + para, windowName, windowType)) == null) {
                    var_proceed = true;
                    return;
                }
                var_proceed = true;
            } else {
                window.location.href = url + "?" + para;
            }
        } else {
            if (method == "post") {
                form.method = method;
                if (form.elements[var_submit_win] != null) {
         //alert(windowName);
                }
                form.elements[var_submit_win].value = escape(windownames);
                if (form.elements[var_ssl] != null) {
                    form.elements[var_ssl].value = cs_isSSL(form.action);
                }
                if (newWin == true) {
                    var_proceed = false;
                    if ((newWindow = windowManagement_openWindow("cs.htm", windowName, windowType)) == null) {
                        var_proceed = true;
                        return;
                    }
                    form.target = windowName;
                    form.submit();
                    var_proceed = true;
                } else {
      //alert("7");   
                    form.target = "SI";
                    form.submit();
                }
            } else {
                return;
            }
        }
    } else {
        alert("Please wait while processing...");
    }
}
/**
 * loads BL Document Manager pages from a BL Document Manager page that has frame implementation 
 */
function cs_submitClickBLFrame(newWin, windowName, windowType, url, form, method, para) {
    if (var_proceed) {
        var_proceed = false;
        windownames = cs_getWindowName(windowName);
        var w_ht = screen_ht - 60;
        var w_wd = screen_wd - 20;
        windowType += "left=10,top=10,screenX=10,screenY=10,";
        windowType += "height=" + w_ht + ",width=" + w_wd;
        if (method == "get") {
            para = var_submit_win + "=" + escape(windownames) + "&" + para + "&" + var_ssl + "=" + cs_isSSL(url);
            if (newWin == true) {
                var_proceed = false;
                if ((newWindow = windowManagement_openWindow(url + "?" + para, windowName, windowType)) == null) {
                    var_proceed = true;
                    return;
                }
                var_proceed = true;
            } else {
                window.location.href = url + "?" + para;
            }
        } else {
            if (method == "post") {
                form.method = method;
                if (form.elements[var_submit_win] != null) {
                    form.elements[var_submit_win].value = escape(windownames);
                }
                if (form.elements[var_ssl] != null) {
                    form.elements[var_ssl].value = cs_isSSL(form.action);
                }
                if (newWin == true) {
                    var_proceed = false;
                    if ((newWindow = windowManagement_openWindow("cs.htm", windowName, windowType)) == null) {
                        var_proceed = true;
                        return;
                    }
                    form.target = windowName;
                    form.submit();
                    var_proceed = true;
                } else {
                    form.target = "_top";
                    form.submit();
                }
            } else {
                return;
            }
        }
    } else {
        alert("Please wait while processing...");
    }
}
/**
 * loads the payment instruction pages, storing the windowHandle piWindow,
 * and provides confirmation box if window already exists
 */
function cs_piClick(newWin, windowName, windowType, url, form, method, para) {
    windownames = cs_getWindowName(windowName);
    var w_ht = screen_ht - 60;
    var w_wd = screen_wd - 20;
    windowType += "left=10,top=10,screenX=10,screenY=10,";
    windowType += "height=" + w_ht + ",width=" + w_wd;
    form.action = url;
    form.method = method;
    if (form.elements[var_submit_win] != null) {
        form.elements[var_submit_win].value = escape(windownames);
    }
    if (form.elements[var_ssl] != null) {
        form.elements[var_ssl].value = cs_isSSL(form.action);
    }
    if (newWin == true) {
        if (piWindow && !piWindow.closed) {
            var confirmMsg = "Are you sure that you want to discard your existing Payment Instructions?";
            var overwriteSettings = confirm(confirmMsg);
            if (!overwriteSettings) {
                return;
            } else {
                piWindow.close();
            }
        }
        if ((piWindow = windowManagement_openWindow("cs.htm", windowName, windowType)) == null) {
            return;
        }
        form.target = windowName;
    } else {
        form.target = "_self";
    }
    form.submit();
}
/**
 * window method used to create a pdfWindow (print window)
 */
function cs_pdfClick(newWin, windowName, windowType, url, form, method, para) {
    if (var_proceed) {
        var_proceed = false;
        windownames = cs_getWindowName(windowName);
        /*
    //TODO - re-implement this code for R21 batch invoice printing
    var w_ht = Math.round(0.7 * screen_ht);
    var w_wd = Math.round(0.7 * screen_wd);
    var w_left = (screen_wd) - 120;
    var w_top=(screen_top)-120;  
    windowType += "left=" + w_left + ",top=" + w_top + ",screenX=" + w_left + ",screenY=" + w_top + ",";
*/
        var w_ht = screen_ht - 60;
        var w_wd = screen_wd - 20;
        windowType += "left=10,top=10,screenX=10,screenY=10,";
        windowType += "height=" + w_ht + ",width=" + w_wd;
        form.action = url;
        form.method = method;
        if (form.elements[var_submit_win] != null) {
            form.elements[var_submit_win].value = escape(windownames);
        }
        if (form.elements[var_ssl] != null) {
            form.elements[var_ssl].value = cs_isSSL(form.action);
        }
        if (newWin == true) {
            if (pdfWindow && !pdfWindow.closed) {
                alert("Please close the pdf file before loading new pdf");
                return;
            } else {
                if (bpWindow && !bpWindow.closed) {
                    alert("Please close the batch print window before loading new pdf");
                    return;
                } else {
                    if ((pdfWindow = windowManagement_openWindow("cs.htm", windowName, windowType)) == null) {
                        return;
                    }
                    form.target = windowName;
                }
            }
        } else {
            form.target = "_self";
        }
        form.submit();
    } else {
        alert("Please wait while processing...");
    }
}
function cs_getWindowName(aWinName) {
    cs_setMyCookie();//for the defect of confirm dialog disalbed the timeOut cs_everyMinute()
    if (aWinName == "") {
        return escape(CONST_WIN_STR + self.name);
    } else {
        return escape(CONST_WIN_STR + aWinName);
    }
}
function cs_generateTempId(windowname) {
    if (windowname.substring(0, 11) == "partnership") {
        partnership_instance++;
        return partnership_instance;
    } else {
        if (windowname.substring(0, 4) == "user") {
            user_instance++;
            return user_instance;
        } else {
            if (windowname.substring(0, 7) == "booking") {
                bkg_instance++;
                return bkg_instance;
            } else {
                if (windowname.substring(0, 5) == "pf_sc") {
                    pf_sc_instance++;
                    return pf_sc_instance;
                } else {
                    if (windowname.substring(0, 5) == "pr_sc") {
                        pr_sc_instance++;
                        return pr_sc_instance;
                    } else {
                        if (windowname.substring(0, 12) == "rpt_template") {
                            rpt_templ_instance++;
                            return rpt_templ_instance;
                        } else {
                            if (windowname.substring(0, 2) == "si") {
                                si_instance++;
                                return si_instance;
                            } else {
                                if (windowname.substring(0, 7) == "siTempl") {
                                    si_templ_instance++;
                                    return si_templ_instance;
                                } else {
                                    if (windowname.substring(0, 7) == "siDraft") {
                                        si_draft_instance++;
                                        return si_draft_instance;
                                    } else {
                                        if (windowname.substring(0, 8) == "view_pa_") {
                                            view_pa_instance++;
                                            return view_pa_instance;
                                        } else {
                                            if (windowname.substring(0, 9) == "view_inv_") {
                                                view_inv_instance++;
                                                return view_inv_instance;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
function cs_confirmCancel(WindowTitle) {
    location.href = contenturl + "errormessages/confirmcancel.htm?" + escape(WindowTitle);
}
function cs_setMyCookie() {
    var winnames = CONST_WIN_STR + self.name;
    cs_everyMinute();
    self.focus();
}
function cs_setSpecialCookie(aWinName) {
    var winnames = CONST_WIN_STR + aWinName;
    cs_everyMinute();
    self.focus();
}
function cs_addCookie(aWinName) {
    var todays_date = new Date();
    var expires_date = new Date(todays_date.getTime() + 20000); // 20 sec from now 
    document.cookie = aWinName + "=" + escape(aWinName) + "; expires=" + expires_date.toGMTString();
}
function cs_deleteCookie(id) {
    var todays_date = new Date();
    var expires_date = new Date(todays_date.getTime() - 365 * 24 * 60 * 60000); // 1 year from now  
    document.cookie = id + "=; expires=" + expires_date.toGMTString();
}
function cs_everyMinute() {
    cs_addCookie(CONST_WIN_STR + self.name);
    setTimeout("cs_everyMinute()", 15000);
}
function cs_closeSelf() {
    cs_deleteCookie("win" + self.name);
}
function cs_resetCookies() {
    if (document.cookie != "") {
        thisCookie = document.cookie.split(";");
        todayDate = new Date();
        expireDate = new Date(todayDate.getTime() - 365 * 24 * 60 * 60000); // 1 year from now 
        for (i = 0; i < thisCookie.length; i++) {
            cookieName = thisCookie[i].split("=")[0];
            cookieValue = thisCookie[i].split("=")[1];
            if (cookieName.substring(0, 1) == " ") {
                aWin = (cookieName.substring(1, 4) == CONST_WIN_STR);
            } else {
                aWin = (cookieName.substring(0, 3) == CONST_WIN_STR);
            }
            if (aWin) {
                if ((cookieValue.substring(3) != self.name) && (cookieValue.substring(3) != CONST_CS_STR_ALL_LOW_CASE)) {
                    document.cookie = cookieName + "=;expires=" + expireDate.toGMTString();
                }
            }
        }
    }
}
function cs_openSample(url, windowname, winsize) {
    winsize = winsize.toUpperCase();
    if (winsize == "S") {
        scalar = 0.33;
    } else {
        if (winsize == "P") {
            scalar = 0.4;
        } else {
            if (winsize == "M") {
                scalar = 0.5;
            } else {
                scalar = 0.75;
            }
        }
    }
    w_ht = Math.round(scalar * screen_ht);
    w_wd = Math.round(scalar * screen_wd);
    w_left = (screen_wd - w_wd) - 20;
    windowparms = "resizable=yes,status=yes,scrollbars=yes,";
    windowparms += "left=" + w_left + ",top=" + screen_top + ",screenX=" + w_left + ",screenY=" + screen_top + ",";
    windowparms += "height=" + w_ht + ",width=" + w_wd;
    if (window.emailWindow) {
        if (!emailWindow.closed) {
            emailWindow.close();
        }
    }
    emailWindow = windowManagement_openWindow(contenturl + url, windowname, windowparms);
    return;
}
function cs_signoff(servleturl) {
    if (confirm("Are you sure you want to sign off?  If you sign off, all the windows for " + CONST_CS_STR + " will be closed.")) {
        if (document.cookie != "") {
            thisCookie = document.cookie.split(";");
            for (i = 0; i < thisCookie.length; i++) {
                cookieName = thisCookie[i].split("=")[0];
                if (cookieName.substring(0, 1) == " ") {
                    cookieName = cookieName.substring(1);
                }
                var winName = "";
                if (cookieName.substring(0, 3) == CONST_WIN_STR) {
                    winName = cookieName.substring(3);
                }
                if (winName != "") {
                    if ((winName != self.name) && (winName != CONST_CS_STR_ALL_LOW_CASE)) {
                        NewWindow = window.open("cs.htm", winName);
                        NewWindow.window.close();
                        cs_deleteCookie(cookieName);
                    }
                }
            }
        }
        cs_getSignOffPage();
        if (self.name != CONST_CS_STR_ALL_LOW_CASE) {
            self.close();
        }
    }
}
function cs_cfsignoff(servleturl) {
    if (confirm("Are you sure you want to sign off?  If you sign off, all the windows for " + CONST_CS_STR + " will be closed.")) {
        if (document.cookie != "") {
            thisCookie = document.cookie.split(";");
            for (i = 0; i < thisCookie.length; i++) {
                cookieName = thisCookie[i].split("=")[0];
                if (cookieName.substring(0, 1) == " ") {
                    cookieName = cookieName.substring(1);
                }
                var winName = "";
                if (cookieName.substring(0, 3) == CONST_WIN_STR) {
                    winName = cookieName.substring(3);
                }
                if (winName != "") {
                    if ((winName != self.name) && (winName != CONST_CS_STR_ALL_LOW_CASE)) {
                        NewWindow = window.open("cs.htm", winName);
                        NewWindow.window.close();
                        cs_deleteCookie(cookieName);
                    }
                }
            }
        }
        cs_cfgetSignOffPage();
        if (self.name != "csc_cargosmart") {
            self.close();
        }
    }
}

function cs2_popupTOU() {
    cs_popupPage(CS2_TOUURL, "L", "cslegal", NONE);
}
function cs2_popupCopyRight() {
    cs_popupPage(CS2_COPYURL, "L", "cslegal", NONE);
}
function cs2_popupPSS() {
    cs_popupPage(CS2_PSSURL, "L", "cslegal", NONE);
}
function oocl_popupExit(url) {
    w_top = Math.round((screen_ht - 300) * 0.5);
    w_left = Math.round((screen_wd - 460) * 0.5);
    winparms = "width=460,height=200,";
    winparms += "left=" + w_left + ",top=" + w_top;
    exitWin = window.open(contenturl + "acZoneExit.htm", "popup", winparms);
    cs_popupPage(url, "X", "noncs", FULL);
    exitWin.focus();
}
