function linkCheck(page, link_val) {
    //var link_val = "TCH:23:2:2.1"
    //var link_val="TCH:23:2"
    //var link_val="TCH:23"
    //var link_val="TCH-23"
    //var link_val="TCH-23:2:2.1"
    //var link_val="TCH-23:2"
    //var link_val="TCH-23"
    //var current_chapter_prefix;
    //var current_chapter_prefix = "TCH-23"
    //var current_chapter_prefix = "TCH:23"
    //var page = "LOOSELEAF";
    //var page = "LAWREPORT";
    var sectionLinkFound = false;
    try {
        if (link_val != null) {
            var newLink = "";
            var firstSemicolon = link_val.indexOf(":");
            if (link_val.indexOf("-") > -1 && link_val.indexOf("-") < firstSemicolon) {
                //alert("link_val:"+link_val);
                if ((page != null) && (current_chapter_prefix != null) && current_chapter_prefix.length > 4 && ((page == "LOOSELEAF") || (page == "BOOK"))) {
                    //alert("document - location.hash current_chapter_prefix:" + current_chapter_prefix);
                    var currentChapterPrefix = current_chapter_prefix.replace(":", "-");
                    if (link_val.indexOf(currentChapterPrefix+":") > -1) {
                        //                        alert("document - location.hash current_chapter_prefix:" + current_chapter_prefix);
                        document.location.hash = link_val;
                        //document.write("local result: " + link_val);
                    }
                    else {
                        window.location.href = "doc.do?citation_dest=" + link_val;
                        //document.write("win result: " + link_val);
                    }
                }
                else {
                    window.location.href = "doc.do?citation_dest=" + link_val;
                    //document.write("no ch result: " + link_val);
                }
            }
            else {
                if ((page == "LOOSELEAF" || page == "BOOK") && current_chapter_prefix != null && current_chapter_prefix.length > 4 && (link_val.indexOf(current_chapter_prefix+":") > -1 )) {
                    //alert("document.location.hash current_chapter_prefix:" + current_chapter_prefix);
                    document.location.hash = link_val;
                    //document.write("local link result: " + link_val)
                } else {
                    var splittedStrs = link_val.split(":");
                    if (splittedStrs != null) {
                        if (splittedStrs.length == 1) {
                            newLink = splittedStrs[0]
                        }
                        else if (splittedStrs.length == 2) {
                            newLink = splittedStrs[0] + "-" + splittedStrs[1];
                        }
                        else if (splittedStrs.length > 2) {
                            for (i = 0; i < splittedStrs.length; i++) {
                                if (i == 1) {
                                    newLink = newLink + "-";
                                }
                                else if (i > 1) {
                                    newLink = newLink + ":";
                                }
                                newLink = newLink + splittedStrs[i];
                            }
                            sectionLinkFound = true;
                        }
                        if (sectionLinkFound) {
                            window.location.href = "doc.do?citation_dest=" + newLink + "#" + link_val;
                        } else {
                            window.location.href = "doc.do?citation_dest=" + newLink;
                        }
                        //document.write("result: " + newLink)
                    } else {
                        window.location.href = "doc.do?citation_dest=" + link_val;
                        //document.write("result: " + link_val)
                    }
                }
            }
        }
    }
    catch(err) {
        window.location.href = "doc.do?citation_dest=" + link_val;
        //document.write("err result: " + link_val)
    }
}
function GoToAnchor(strAnchorName) {
    window.location.href = "#" + strAnchorName;
}
function openEmailAFriend(citation, title, page_num) {
    appWindow = window.open("emailAFriend_pop.jsp?citation_dest=" + citation + "&title=" + title + "&page_num=" + page_num, "", "toolbar=no,location=no,status=no,menubar=no,directories=no,scrollbars=no,resizable=yes,width=515,height=550");
    appWindow.focus();
}
function openHelp(anchor) {
     window.open("/ipiportal/helppage.html#" + anchor, "", "toolbar=no,location=no,status=no,menubar=no,directories=no,scrollbars=yes,resizable=no,width=515,height=550");
    //window.open("help.do?methodToCall=getDocumentResource&display_name=ILAW_HELP&return_page=help_page#" + anchor, "", "toolbar=no,location=no,status=no,menubar=no,directories=no,scrollbars=yes,resizable=no,width=515,height=550");
    //appWindow = window.open("help.do?methodToCall=getDocumentResource&display_name=ILAW_HELP&return_page=help_page#" + anchor, "", "toolbar=no,location=no,status=no,menubar=no,directories=no,scrollbars=yes,resizable=no,width=515,height=550");
    //appWindow.focus();
}
function openNotesAndExplanationsHelp(anchor) {
    appWindow = window.open("maritime_notes.html#" + anchor, "", "toolbar=no,location=no,status=no,menubar=no,directories=no,scrollbars=yes,resizable=no,width=515,height=550");
    appWindow.focus();
}
function openPopup(url,w,h,x,y){
window.open(url,"","resizable=no,toolbar=no,scrollbars=no,menubar=no,status=no,directories=no,width="+w+",height="+h+",left="+x+",top="+y+"");
}



