/*  MyCloud1.js
 *
 *  Purpose:
 *  ----------------------------------------------------------------------------
 *  This defines the JavaScript functions called throughout the My McCloud site.
 *
 *  functions:
 *  ----------------------------------------------------------------------------
 *  function on_click_MyC_Best_Help(flag)
 *  function on_click_MyC_Best_Pick()
 *  function on_click_MyC_Best_Text(what)
 *  function on_submit_MyC_Best_Test()
 *  function on_submit_MyC_Best_View()
 *  function on_submit_MyC_Reso()
 *  window.onload = function()
 *
 *  History:
 *  ----------------------------------------------------------------------------
 *  06-Oct-2008.1  Changed re "window.onload()" added.
 *  06-Oct-2008.0  Changed re "function on_click_MyC_Best_Pick()" added.
 *  03-Oct-2008.0  Changed re "document.forms[0]" now "document.forms["MyC_?"]".
 *  13-Jun-2008.0  Changed re "function on_submit_MyC_Reso()".
 *  19-May-2008.0  Changed.
 *  18-May-2008.0  Created.
 *  ----------------------------------------------------------------------------
 */

/*
 *  Global Constants and Variables
 */

function on_click_MyC_Best_Help(flag) {
/*
 *  on_click_MyC_Best_Help()
 */
    var what = "";
    if (flag == 1) {
        what += "Search for:\n\n";
        what += "Enter a search word or phrase.\n\n";
        what += "Separate words/phrases with ' + '\n";
        what += "to find files with all words/phrases.\n\n";
        what += "Extra spaces are automatically removed.";
    } else if (flag == 2) {
        what += "Match case?\n\n";
        what += "Check the checkbox for a 'case-sensitive' search;\n";
        what += "otherwise, the search is 'case-insensitive'.\n\n";
        what += "For example, a search on 'mccloud services' returns:\n";
        what += "zero matches if the search is case-sensitive but\n";
        what += "many matches if the search is case-insensitive\n";
        what += "because 'McCloud Services' is always captialized.";
    }
    alert(what);
}

function on_click_MyC_Best_Pick() {
/*
 *  on_click_MyC_Best_Pick()
 */
    var pick = document.getElementById("SearchSelect").value;
    if (pick == "") return;
    window.open("pdfs/" + file,"PDF","left=0,top=0,left=0,resizable");
}

function on_click_MyC_Best_Text(what) {
/*
 *  on_click_MyC_Best_Text()
 */
    if (what == 0) {
        document.getElementById("SearchText").value = "";
    } else {
        document.getElementById("SearchText").value = document.getElementById("SearchLast").value;

    }
}

function on_submit_MyC_Best_Test() {
/*
 *  function on_submit_MyC_Best_Test()
 */
    var spc1 = false;
    var spc2 = false;
    var what = document.getElementById("SearchText").value;
    if (what.length > 1) {
        if (what.charAt(0) == " ") spc1 = true;
        if (what.charAt(what.length-1) == " ") spc2 = true;
    }
    var rex1 = /\s{2,}/g;                               // replace spaces
    var rex2 = /^(\s*)([\W\w]*)(\b\s*$)/;               // trim spaces
        what = what.replace(rex1," ");
        what = what.replace(rex2,"$2");
    if (spc1) what = " " + what;
    if (spc2) what = what + " ";
    document.getElementById("SearchText").value = what;
    var test = what.replace(/\</g,"[");
        test = test.replace(/\>/g,"]");
    if (what != "" && what == test && what.length > 2) return true;
    alert("'Search for' is either missing or invalid!");
    return false;
}

function on_submit_MyC_Best_View() {
/*
 *  function on_submit_MyC_Best_View()
 */
    var form = document.forms["MyC_Best"];
    var pick = form.PDF.selectedIndex;
    if (pick < 1) return false;
    var file = form.PDF.options[pick].value;
    if (file == "") return false;
    window.open("pdfs/" + file,"PDF","left=0,top=0,left=0,resizable");
    return false;
}

function on_submit_MyC_Reso() {
/*
 *  function on_submit_MyC_Reso()
 */
    var form = document.forms["MyC_Reso"];
    var pick = form.URL.selectedIndex;
    if (pick < 1) return false;
    var file = form.URL.options[pick].value;
    if (file == "") return false;
    window.open(file,"","left=0,top=0,width=800,height=600,location,menubar,resizable,scrollbars,toolbar");
    return false;
}

window.onload = function() {
/*
 *  function window.onload()
 */
    var qstr = location.search;
    if (qstr == "") return;
    if (qstr.length != 7) return;
    if (qstr.substring(1,6) != "panel") return;
    var panl = qstr.substr(6)
    panel(panl);
}
