/************************************************************************
 * JavaScript code Copyright (c) 2005-2010 St. Norbert College      *
 *      - Scott Crevier, St. Norbert College, 16-Jul-2010   *
 ************************************************************************/
function leapto(form) {
    var s = form.url.options[form.url.selectedIndex].value;
    switch (s.substr(0,1)) {
        case '/':
            location = 'http://www.snc.edu' + s;
            break;
        case 'h':
            location = s;
            break;
        default:
            alert("That option '" + s + "' not supported.");
            break;
    }
}

/************************************************************************
 *  Various functions to format strings and digits.         *
 ************************************************************************/
function capitalizeString(str) {
    return str.substr(0,1).toUpperCase() + str.substr(1,str.length - 1).toLowerCase();
}

function twoDigits(num) {
    num = parseInt(num,10);
    if (num < 10) {
        return '0' + num;
    } else {
        return num;
    }
}

function doFloat(value) {
    if (value == '') value = 0;
    return parseFloat(value);
}

function fmtMoney(value) {
    if (value == '') value = 0;
    value -= 0;
    value = (Math.round(value*100))/100;
    return (value == Math.floor(value)) ? value + '.00' : ( (value*10 == Math.floor(value*10)) ? value + '0' : value);
}

function commas(S) {
    var commaRegEx = /^(.* )?([-+\u00A3\u20AC]?\d+)(\d{3}\b)/;
    S = String(S);
    return S == (S=S.replace(commaRegEx, "$1$2,$3")) ? S : commas(S);
}

/************************************************************************
 *  Create a select box for years.                  *
 ************************************************************************/
function yearOptions(from,to,firstval,firstshow) {

    // **************************************************************
    // *  Define some variables for the year selection.     *
    // **************************************************************
    var i, code;
    var now   = new Date();
    var yyyy  = now.getFullYear();

    // **************************************************************
    // *  Write the year field.                 *
    // **************************************************************
    document.writeln("<select name=\"year\" size=\"1\">");

    if (firstshow != "") {
        code    = "<option value=\"" + firstval + "\">" + firstshow + "</option>";
        document.writeln(code);
    }

    for (i=from; i<=to; i++) {
        y = (yyyy + i);

        code    = "<option value=\"" + y + "\">" + y + "</option>";
        document.writeln(code);
    }

    document.writeln("</select>");
}

/************************************************************************
 *  Create a select box for months.                 *
 ************************************************************************/
function monthOptions(firstval,firstshow) {

    // **************************************************************
    // *  Define some variables for the month selection.        *
    // **************************************************************
    var i,num,code;
    var xmon = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");

    // **************************************************************
    // *  Write the month field.                    *
    // **************************************************************
    document.writeln("<select name=\"month\" size=\"1\">");

    if (firstshow != "") {
        code    = "<option value=\"" + firstval + "\">" + firstshow + "</option>";
        document.writeln(code);
    }

    for (i=0; i<xmon.length; i++) {

        num = (i + 1);
        if (num < 10) {
            num = "0" + num;
        }

        code    = "<option value=\"" + num + "\">" + xmon[i] + "</option>";
        document.writeln(code);
    }

    document.writeln("</select>");
}

/************************************************************************
 *  Create a select box for numbers.                    *
 ************************************************************************/
function numberOptions(from,to,firstval,firstshow) {

    // **************************************************************
    // *  Define some variables for the year selection.     *
    // **************************************************************
    var num, code;

    // **************************************************************
    // *  Write the year field.                 *
    // **************************************************************
    document.writeln("<select name=\"number\" size=\"1\">");

    if (firstshow != "") {
        code    = "<option value=\"" + firstval + "\">" + firstshow + "</option>";
        document.writeln(code);
    }

    for (num=from; num<=to; num++) {
        code    = "<option value=\"" + num + "\">" + num + "</option>";
        document.writeln(code);
    }

    document.writeln("</select>");
}

/************************************************************************
 *  Create a select box for credit card expire date.            *
 ************************************************************************/
function ccExpireOptions() {

    // **************************************************************
    // *  Define some variables for the month selection.        *
    // **************************************************************
    var i,num,code;
    var xmon = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");

    // **************************************************************
    // *  Write the month field.                    *
    // **************************************************************
    document.writeln("<select name=\"cc_expmm\" size=\"1\">");
    document.writeln("<option value=\"\">--</option>");

    for (i=0; i<xmon.length; i++) {

        num = (i + 1);
        if (num < 10) {
            num = "0" + num;
        }

        code    = "<option value=\"" + num + "\">" + xmon[i] + "</option>";
        document.writeln(code);
    }

    document.writeln("</select>");

    // **************************************************************
    // *  Define some variables for the year selection.     *
    // **************************************************************
    var years = 8;
    var now   = new Date();
    var yyyy  = now.getFullYear();

    //alert(yyyy);

    // **************************************************************
    // *  Write the year field.                 *
    // **************************************************************
    document.writeln("<select name=\"cc_expyyyy\" size=\"1\">");
    document.writeln("<option value=\"\">--</option>");

    for (i=0; i<years; i++) {
        y = (yyyy + i);

        code    = "<option value=\"" + y + "\">" + y + "</option>";
        document.writeln(code);
    }

    document.writeln("</select>");
}

/************************************************************************
 *  Create a select box of countries.                   *
 *  http://www.iso.org/iso/country_codes/iso_3166_code_lists.htm    *
 ************************************************************************/
function countryOptions() {

    // **************************************************************
    // *  Define the country list.                  *
    // **************************************************************
    var cy = new Array();

    cy[0] = "AF|Afghanistan";
    cy[1] = "AL|Albania";
    cy[2] = "DZ|Algeria";
    cy[3] = "AS|American Samoa";
    cy[4] = "AD|Andorra";
    cy[5] = "AO|Angola";
    cy[6] = "AI|Anguilla";
    cy[7] = "AQ|Antarctica";
    cy[8] = "AG|Antigua and Barbuda";
    cy[9] = "AR|Argentina";
    cy[10] = "AM|Armenia";
    cy[11] = "AW|Aruba";
    cy[12] = "AU|Australia";
    cy[13] = "AT|Austria";
    cy[14] = "AZ|Azerbaijan";
    cy[15] = "BS|Bahamas";
    cy[16] = "BH|Bahrain";
    cy[17] = "BD|Bangladesh";
    cy[18] = "BB|Barbados";
    cy[19] = "BY|Belarus";
    cy[20] = "BE|Belgium";
    cy[21] = "BZ|Belize";
    cy[22] = "BJ|Benin";
    cy[23] = "BM|Bermuda";
    cy[24] = "BT|Bhutan";
    cy[25] = "BO|Bolivia";
    cy[26] = "BA|Bosnia and Herzegowina";
    cy[27] = "BW|Botswana";
    cy[28] = "BV|Bouvet Island";
    cy[29] = "BR|Brazil";
    cy[30] = "IO|British Indian Ocean Territory";
    cy[31] = "BN|Brunei Darussalam";
    cy[32] = "BG|Bulgaria";
    cy[33] = "BF|Burkina Faso";
    cy[34] = "BI|Burundi";
    cy[35] = "KH|Cambodia";
    cy[36] = "CM|Cameroon";
    cy[37] = "CA|Canada";
    cy[38] = "CV|Cape Verde";
    cy[39] = "KY|Cayman Islands";
    cy[40] = "CF|Central African Republic";
    cy[41] = "TD|Chad";
    cy[42] = "CL|Chile";
    cy[43] = "CN|China";
    cy[44] = "CX|Christmas Island";
    cy[45] = "CC|Cocos (Keeling) Islands";
    cy[46] = "CO|Colombia";
    cy[47] = "KM|Comoros";
    cy[48] = "CG|Congo";
    cy[49] = "CK|Cook Islands";
    cy[50] = "CR|Costa Rica";
    cy[51] = "CI|Cote D&#39;Ivoire";
    cy[52] = "HR|Croatia (local name: Hrvatska)";
    cy[53] = "CU|Cuba";
    cy[54] = "CY|Cyprus";
    cy[55] = "CZ|Czech Republic";
    cy[56] = "DK|Denmark";
    cy[57] = "DJ|Djibouti";
    cy[58] = "DM|Dominica";
    cy[59] = "DO|Dominican Republic";
    cy[60] = "TP|East Timor";
    cy[61] = "EC|Ecuador";
    cy[62] = "EG|Egypt";
    cy[63] = "SV|El Salvador";
    cy[64] = "GQ|Equatorial Guinea";
    cy[65] = "ER|Eritrea";
    cy[66] = "EE|Estonia";
    cy[67] = "ET|Ethiopia";
    cy[68] = "FK|Falkland Islands (Malvinas)";
    cy[69] = "FO|Faroe Islands";
    cy[70] = "FJ|Fiji";
    cy[71] = "FI|Finland";
    cy[72] = "FR|France";
    cy[73] = "GF|French Guiana";
    cy[74] = "PF|French Polynesia";
    cy[75] = "TF|French Southern Territories";
    cy[76] = "GA|Gabon";
    cy[77] = "GM|Gambia";
    cy[78] = "GE|Georgia";
    cy[79] = "DE|Germany";
    cy[80] = "GH|Ghana";
    cy[81] = "GI|Gibraltar";
    cy[82] = "GR|Greece";
    cy[83] = "GL|Greenland";
    cy[84] = "GD|Grenada";
    cy[85] = "GP|Guadeloupe";
    cy[86] = "GU|Guam";
    cy[87] = "GT|Guatemala";
    cy[88] = "GN|Guinea";
    cy[89] = "GW|Guinea-Bissau";
    cy[90] = "GY|Guyana";
    cy[91] = "HT|Haiti";
    cy[92] = "HM|Heard and Mc Donald Islands";
    cy[93] = "HN|Honduras";
    cy[94] = "HK|Hong Kong";
    cy[95] = "HU|Hungary";
    cy[96] = "IS|Iceland";
    cy[97] = "IN|India";
    cy[98] = "ID|Indonesia";
    cy[99] = "IR|Iran (Islamic Republic of)";
    cy[100] = "IQ|Iraq";
    cy[101] = "IE|Ireland";
    cy[102] = "IL|Israel";
    cy[103] = "IT|Italy";
    cy[104] = "JM|Jamaica";
    cy[105] = "JP|Japan";
    cy[106] = "JO|Jordan";
    cy[107] = "KZ|Kazakhstan";
    cy[108] = "KE|Kenya";
    cy[109] = "KI|Kiribati";
    cy[110] = "KP|Korea, Democratic People&#39;s Republic of";
    cy[111] = "KR|Korea, Republic of";
    cy[112] = "KW|Kuwait";
    cy[113] = "KG|Kyrgyzstan";
    cy[114] = "LA|Lao People&#39;s Democratic Republic";
    cy[115] = "LV|Latvia";
    cy[116] = "LB|Lebanon";
    cy[117] = "LS|Lesotho";
    cy[118] = "LR|Liberia";
    cy[119] = "LY|Libyan Arab Jamahiriya";
    cy[120] = "LI|Liechtenstein";
    cy[121] = "LT|Lithuania";
    cy[122] = "LU|Luxembourg";
    cy[123] = "MO|Macau";
    cy[124] = "MK|Macedonia, the former Yugoslav Republic of";
    cy[125] = "MG|Madagascar";
    cy[126] = "MW|Malawi";
    cy[127] = "MY|Malaysia";
    cy[128] = "MV|Maldives";
    cy[129] = "ML|Mali";
    cy[130] = "MT|Malta";
    cy[131] = "MH|Marshall Islands";
    cy[132] = "MQ|Martinique";
    cy[133] = "MR|Mauritania";
    cy[134] = "MU|Mauritius";
    cy[135] = "YT|Mayotte";
    cy[136] = "MX|Mexico";
    cy[137] = "FM|Micronesia, Federated States of";
    cy[138] = "MD|Moldova, Republic of";
    cy[139] = "MC|Monaco";
    cy[140] = "MN|Mongolia";
    cy[141] = "MS|Montserrat";
    cy[142] = "MA|Morocco";
    cy[143] = "MZ|Mozambique";
    cy[144] = "MM|Myanmar";
    cy[145] = "NA|Namibia";
    cy[146] = "NR|Nauru";
    cy[147] = "NP|Nepal";
    cy[148] = "NL|The Netherlands";
    cy[149] = "NC|New Caledonia";
    cy[150] = "NZ|New Zealand";
    cy[151] = "NI|Nicaragua";
    cy[152] = "NE|Niger";
    cy[153] = "NG|Nigeria";
    cy[154] = "NU|Niue";
    cy[155] = "NF|Norfolk Island";
    cy[156] = "MP|Northern Mariana Islands";
    cy[157] = "NO|Norway";
    cy[158] = "OM|Oman";
    cy[159] = "PK|Pakistan";
    cy[160] = "PW|Palau";
    cy[161] = "PA|Panama";
    cy[162] = "PG|Papua New Guinea";
    cy[163] = "PY|Paraguay";
    cy[164] = "PE|Peru";
    cy[165] = "PH|Philippines";
    cy[166] = "PN|Pitcairn";
    cy[167] = "PL|Poland";
    cy[168] = "PT|Portugal";
    cy[169] = "PR|Puerto Rico";
    cy[170] = "QA|Qatar";
    cy[171] = "RE|Reunion";
    cy[172] = "RO|Romania";
    cy[173] = "RU|Russian Federation";
    cy[174] = "RW|Rwanda";
    cy[175] = "KN|Saint Kitts and Nevis";
    cy[176] = "LC|Saint Lucia";
    cy[177] = "VC|Saint Vincent and the Grenadines";
    cy[178] = "WS|Samoa";
    cy[179] = "SM|San Marino";
    cy[180] = "ST|Sao Tome and Principe";
    cy[181] = "SA|Saudi Arabia";
    cy[182] = "SN|Senegal";
    cy[183] = "SC|Seychelles";
    cy[184] = "SL|Sierra Leone";
    cy[185] = "SG|Singapore";
    cy[186] = "SK|Slovakia (Slovak Republic)";
    cy[187] = "SI|Slovenia";
    cy[188] = "SB|Solomon Islands";
    cy[189] = "SO|Somalia";
    cy[190] = "ZA|South Africa";
    cy[191] = "ES|Spain";
    cy[192] = "LK|Sri Lanka";
    cy[193] = "SH|St. Helena";
    cy[194] = "PM|St. Pierre and Miquelon";
    cy[195] = "SD|Sudan";
    cy[196] = "SR|Suriname";
    cy[197] = "SJ|Svalbard and Jan Mayen Islands";
    cy[198] = "SZ|Swaziland";
    cy[199] = "SE|Sweden";
    cy[200] = "CH|Switzerland";
    cy[201] = "SY|Syrian Arab Republic";
    cy[202] = "TW|Taiwan";
    cy[203] = "TJ|Tajikistan";
    cy[204] = "TZ|Tanzania, United Republic of";
    cy[205] = "TH|Thailand";
    cy[206] = "TG|Togo";
    cy[207] = "TK|Tokelau";
    cy[208] = "TO|Tonga";
    cy[209] = "TT|Trinidad and Tobago";
    cy[210] = "TN|Tunisia";
    cy[211] = "TR|Turkey";
    cy[212] = "TM|Turkmenistan";
    cy[213] = "TC|Turks and Caicos Islands";
    cy[214] = "TV|Tuvalu";
    cy[215] = "UG|Uganda";
    cy[216] = "UA|Ukraine";
    cy[217] = "AE|United Arab Emirates";
    cy[218] = "GB|United Kingdom";
    cy[219] = "US|United States";
    cy[220] = "UM|United States Minor Outlying Islands";
    cy[221] = "UY|Uruguay";
    cy[222] = "UZ|Uzbekistan";
    cy[223] = "VU|Vanuatu";
    cy[224] = "VA|Vatican City State (Holy See)";
    cy[225] = "VE|Venezuela";
    cy[226] = "VN|Viet NAM";
    cy[227] = "VG|Virgin Islands (British)";
    cy[228] = "VI|Virgin Islands (U.S.)";
    cy[229] = "WF|Wallis And Futuna Islands";
    cy[230] = "EH|Western Sahara";
    cy[231] = "YE|Yemen";
    cy[232] = "YU|Yugoslavia";
    cy[233] = "ZR|Zaire";
    cy[234] = "ZM|Zambia";
    cy[235] = "ZW|Zimbabwe";

    // **************************************************************
    // *  Write the country field.                  *
    // **************************************************************
    //document.writeln("<select name=\"country\" size=\"1\">");
    document.writeln("<option value=\"\">- select -</option>");

    for (i=0; i<cy.length; i++) {
        v = cy[i];
        f = v.split('|');

        code = f[0];
        name = f[1];

        code    = "<option value=\"" + code + "\">" + name + "</option>";
        document.writeln(code);
    }

    //document.writeln("</select>");

}

/************************************************************************
 *  Create a select box of states/provinces.                *
 *  http://www.usps.com/ncsc/lookups/abbr_state.txt         *
 *  http://www.canadapost.ca/tools/pg/manual/PGaddress-e.asp#1380608    #
 ************************************************************************/
function stateOptions() {
    var coun,code,name,prev_cname,cname,c;

    var opt     = new Array();
    opt["US"]   = 0;
    opt["MI"]   = 0;
    opt["CA"]   = 0;
    opt["OT"]   = 0;

    var type    = new Array();
    type["US"]  = "United States";
    type["MI"]  = "Military";
    type["CA"]  = "Canada";
    type["OT"]  = "Others";

    var st  = new Array();
    st[0]   = "US|AK|Alaska";
    st[1]   = "US|AL|Alabama";
    st[2]   = "US|AR|Arkansas";
    st[3]   = "US|AZ|Arizona";
    st[4]   = "US|CA|California";
    st[5]   = "US|CO|Colorado";
    st[6]   = "US|CT|Connecticut";
    st[7]   = "US|DC|Dist. Of Columbia";
    st[8]   = "US|DE|Delaware";
    st[9]   = "US|FL|Florida";
    st[10]  = "US|GA|Georgia";
    st[11]  = "US|HI|Hawaii";
    st[12]  = "US|IA|Iowa";
    st[13]  = "US|ID|Idaho";
    st[14]  = "US|IL|Illinois";
    st[15]  = "US|IN|Indiana";
    st[16]  = "US|KS|Kansas";
    st[17]  = "US|KY|Kentucky";
    st[18]  = "US|LA|Louisiana";
    st[19]  = "US|MA|Massachusetts";
    st[20]  = "US|MD|Maryland";
    st[21]  = "US|ME|Maine";
    st[22]  = "US|MI|Michigan";
    st[23]  = "US|MN|Minnesota";
    st[24]  = "US|MO|Missouri";
    st[25]  = "US|MS|Mississippi";
    st[26]  = "US|MT|Montana";
    st[27]  = "US|NC|North Carolina";
    st[28]  = "US|ND|North Dakota";
    st[29]  = "US|NE|Nebraska";
    st[30]  = "US|NH|New Hampshire";
    st[31]  = "US|NJ|New Jersey";
    st[32]  = "US|NM|New Mexico";
    st[33]  = "US|NV|Nevada";
    st[34]  = "US|NY|New York";
    st[35]  = "US|OH|Ohio";
    st[36]  = "US|OK|Oklahoma";
    st[37]  = "US|OR|Oregon";
    st[38]  = "US|PA|Pennsylvania";
    st[39]  = "US|RI|Rhode Island";
    st[40]  = "US|SC|South Carolina";
    st[41]  = "US|SD|South Dakota";
    st[42]  = "US|TN|Tennessee";
    st[43]  = "US|TX|Texas";
    st[44]  = "US|UT|Utah";
    st[45]  = "US|VA|Virginia";
    st[46]  = "US|VT|Vermont";
    st[47]  = "US|WA|Washington";
    st[48]  = "US|WI|Wisconsin";
    st[49]  = "US|WV|West Virginia";
    st[50]  = "US|WY|Wyoming";
    st[51]  = "MI|AE|Armed Forces Africa";
    st[52]  = "MI|AA|Armed Forces Americas";
    st[53]  = "MI|AE|Armed Forces Canada";
    st[54]  = "MI|AE|Armed Forces Europe";
    st[55]  = "MI|AE|Armed Forces Middle East";
    st[56]  = "MI|AP|Armed Forces Pacific";
    st[57]  = "CA|AB|Alberta";
    st[58]  = "CA|BC|British Columbia";
    st[59]  = "CA|MB|Manitoba";
    st[60]  = "CA|NB|New Brunswick";
    st[61]  = "CA|NF|Newfoundland";
    st[62]  = "CA|NS|Nova Scotia";
    st[63]  = "CA|NT|Northwest Territories";
    st[64]  = "CA|NU|Nunavut";
    st[65]  = "CA|ON|Ontario";
    st[66]  = "CA|PE|Prince Edward Island";
    st[67]  = "CA|QC|Quebec";
    st[68]  = "CA|SK|Saskatchewan";
    st[69]  = "CA|YT|Yukon Territory";
    st[70]  = "OT|AS|American Samoa";
    st[71]  = "OT|BA|Bahama Islands";
    st[72]  = "OT|BM|Caribbean Islands";
    st[73]  = "OT|CI|Cayman Islands";
    st[74]  = "OT|DR|Dominican Republic";
    st[75]  = "OT|FM|Federated States of Micronesia";
    st[76]  = "OT|GU|Guam";
    st[77]  = "OT|JM|Jamaica Island";
    st[78]  = "OT|MH|Marshall Islands";
    st[79]  = "OT|MP|Northern Mariana Islands";
    st[80]  = "OT|PR|Puerto Rico";
    st[81]  = "OT|PW|Palau";
    st[82]  = "OT|TR|Trinidad And Tobago";
    st[83]  = "OT|VI|Virgin Islands";

    // **************************************************************
    for (i=0; i<arguments.length; i++) {
        c = arguments[i];
        opt[c] = 1;
    }

    // **************************************************************
    // *  Write the options.                    *
    // **************************************************************
    //document.writeln("<select name=\"state\" size=\"1\">");
    document.writeln("<option value=\"\">- select -</option>");

    prev_cname = '';
    for (i=0; i<st.length; i++) {
        v = st[i];
        f = v.split('|');

        coun = f[0];
        code = f[1];
        name = f[2];

        if (opt[coun] == 1) {
            cname = type[coun];

            if (cname != prev_cname) {
                if (i > 0) {
                    document.writeln("</optgroup>");
                }
                document.writeln("<optgroup label=\"" + cname + "\">");
            }

            document.writeln("<option value=\"" + code + "\">" + name + "</option>");
            prev_cname = cname;
        }
    }

    document.writeln("</optgroup>");
    //document.writeln("</select>");
}


/************************************************************************
 *  Display a timer that counts down to a specific date/time.       *
 ************************************************************************/
var xstamp;
var xformat;
var xpretext;
var xposttext;
var xdone;
var xtitle;
var snctzo = 300;   // minutes between SNC time zone and GMT
var placeholderset = 0;
var hosturl = 'http://www.snc.edu';

// central tzo, summer time: 300 (mins)
// pacific tzo, summer time: 420 (mins)

function runCountdown() {
    var date,now,diff,str,tzo;
    var days,hrs,mins,secs;
    var w_days,w_hrs,w_mins,w_secs;

    //alert('smc');
    //return;

    /****************************************************************
     *  If we have the IE bug, bail.                *
     ****************************************************************/
    if (ieBugBrowser()) {
        return;
    }

    /****************************************************************
     *  Handle the arguments.                   *
     ****************************************************************/
    if (arguments.length > 0) {
        xstamp      = arguments[0];
        xformat     = arguments[1];
        xpretext    = arguments[2];
        xposttext   = arguments[3];
        xdone       = arguments[4];
        xtitle      = arguments[5];
    }

    if (xstamp == null) {
        usethis('runCountdown function called without proper arguments');
        return;
    }

    /****************************************************************
     *  Get the difference between the date and now.        *
     ****************************************************************/
    date    = new Date(xstamp);
    now = new Date();
    diff    = ((date.getTime() - now.getTime()) / 1000);    // seconds

    /****************************************************************
     *  Account for the time zone difference between the        *
     *  visitor and SNC.                        *
     ****************************************************************/
    tzo = now.getTimezoneOffset();  // minutes between local time zone and GMT
    diff    = (diff - ((tzo - snctzo) * 60));

    // **************************************************************
    // *  If the date has past, end this now.           *
    // **************************************************************
    if (diff < 0) {
        usethis(xdone);
        if (xformat.indexOf("/") == 0) showCountdownPlaceHolder(xformat,xpretext);
        return;
    }

    /****************************************************************
     *  Calculate the individual values of the countdown timer. *
     ****************************************************************/
    days    = Math.floor(diff / (60 * 60 * 24));
    diff    = (diff - (days * 60 * 60 * 24));

    hrs = Math.floor(diff / (60 * 60));
    diff    = (diff - (hrs * 60 * 60));

    mins    = Math.floor(diff / 60);
    diff    = (diff - (mins * 60));

    secs    = Math.floor(diff);

    /****************************************************************
     *  Max number of days we handle is 999.            *
     ****************************************************************/
    if (days > 999) days = 999;

    /****************************************************************
     *  Format the string accordingly. We're either going to use    *
     *  digit images or a text string.              *
     ****************************************************************/
    if (xformat.indexOf("/") == 0) { 
        /********************************************************
         *  Use images.                     *
         ********************************************************/

        /********************************************************
         *  Show the place holder images if we haven't yet  *
         *  done so.                        *
         ********************************************************/
        if (placeholderset != 1) {
            showCountdownPlaceHolder(xformat,xpretext);
            placeholderset = 1;
        }

        /********************************************************
         *  Pad the values with zeroes as needed.       *
         ********************************************************/
        if (days < 10)  days = '0' + days;
        if (days < 100) days = '0' + days;
        if (hrs  < 10)  hrs  = '0' + hrs;
        if (mins < 10)  mins = '0' + mins;
        if (secs < 10)  secs = '0' + secs;

        /********************************************************
         *  Convert values to strings for ease of handling. *
         ********************************************************/
        days    = days.toString();
        hrs = hrs.toString();
        mins    = mins.toString();
        secs    = secs.toString();

        /********************************************************
         *  Update the timer value.             *
         ********************************************************/
        showCountdownDigits(xformat,days,hrs,mins,secs);

    } else {
        /********************************************************
         *  Use a text string.                  *
         ********************************************************/
        if (xformat == "a") {
            w_days  = (days == 1) ? 'day'    : 'days';
            w_hrs   = (hrs  == 1) ? 'hour'   : 'hours';
            w_mins  = (mins == 1) ? 'minute' : 'minutes';
            w_secs  = (secs == 1) ? 'second' : 'seconds';

            str = commas(days) + " " + w_days + ", "
                + hrs  + " " + w_hrs  + ", "
                + mins + " " + w_mins + ", "
                + secs + " " + w_secs;
        }

        else if (xformat == "b") {
            if (hrs  < 10)  { hrs  = '0' + hrs; }
            if (mins < 10)  { mins = '0' + mins; }
            if (secs < 10)  { secs = '0' + secs; }
            str = days + " " + hrs + ":" + mins + ":" + secs;
        }

        else if (xformat == "d") {
            w_days  = (days == 1) ? 'day'    : 'days';
            str = commas(days) + " " + w_days;
        }

        /********************************************************
         *  Use the string we created.              *
         ********************************************************/
        usethis(xpretext + str + xposttext);
    }

    /****************************************************************
     *  Recursive.                          *
     ****************************************************************/
    setTimeout("runCountdown()",1000);
}

/************************************************************************
 *  Update the text timer/title as directed.                *
 ************************************************************************/
function usethis(str) {
    if (document.layers) {
        // str = 'NN4:' + str;
        //if (xformat.indexOf("/") != 0) document.layers.countdowntitle.document.write(xtitle);
        //document.layers.countdowntitle.document.close();
        document.layers.countdown.document.write(str);
        document.layers.countdown.document.close();
    } else if (document.all) {
        // str = 'IE4:' + str;
        //if (xformat.indexOf("/") != 0) countdowntitle.innerHTML = xtitle;
        countdown.innerHTML = str;
    } else if (document.getElementById) {
        // str = 'v5+:' + str;
        //if (xformat.indexOf("/") != 0) document.getElementById('countdowntitle').firstChild.data = xtitle;
        document.getElementById('countdown').firstChild.data = str;
    }
}

/************************************************************************
 *  Display initial timer images (zeroes), with name attributes so that *
 *  they can then be updated via the countdown timer functionality. *
 ************************************************************************/
function showCountdownPlaceHolder(baseurl,title) {
    var img_space, img_placeholder, url;

    url = hosturl + baseurl;

    img_space = '<img src="' + url + '/space.gif" alt="' + title + '" title="' + title + '" />';

    img_placeholder = img_space
            + '<img src="' + url + '/0.gif" name="d0" alt="' + title + '" title="' + title + '" />'
            + '<img src="' + url + '/0.gif" name="d1" alt="' + title + '" title="' + title + '" />'
            + '<img src="' + url + '/0.gif" name="d2" alt="' + title + '" title="' + title + '" />'
            + img_space
            + '<img src="' + url + '/0.gif" name="h0" alt="' + title + '" title="' + title + '" />'
            + '<img src="' + url + '/0.gif" name="h1" alt="' + title + '" title="' + title + '" />'
            + img_space
            + '<img src="' + url + '/0.gif" name="m0" alt="' + title + '" title="' + title + '" />'
            + '<img src="' + url + '/0.gif" name="m1" alt="' + title + '" title="' + title + '" />'
            + img_space
            + '<img src="' + url + '/0.gif" name="s0" alt="' + title + '" title="' + title + '" />'
            + '<img src="' + url + '/0.gif" name="s1" alt="' + title + '" title="' + title + '" />'
            + img_space
            + '<br/>'
            + '<img src="' + url + '/days.gif" alt="' + title + '" title="' + title + '" />'
            + '<img src="' + url + '/hours.gif" alt="' + title + '" title="' + title + '" />'
            + '<img src="' + url + '/minutes.gif" alt="' + title + '" title="' + title + '" />'
            + '<img src="' + url + '/seconds.gif" alt="' + title + '" title="' + title + '" />';

    document.write(img_placeholder);
}


/************************************************************************
 *  Update the timer images with new digits provided.           *
 ************************************************************************/
function showCountdownDigits(baseurl,days,hrs,mins,secs) {
    var i,char,img_url,url;

    url = hosturl + baseurl;

    /****************************************************************
     *  Update the images.                      *
     ****************************************************************/
    for (i = 0; i < days.length; i++) {
        char = days.charAt(i); 
        img_url = url + '/' + char + '.gif';

        switch(i) {
            case 0:
                document.d0.src = img_url;
                break;
            case 1:
                document.d1.src = img_url;
                break;
            case 2:
                document.d2.src = img_url;
        }
    }

    for (i = 0; i < hrs.length; i++) {
        char = hrs.charAt(i); 
        img_url = url + '/' + char + '.gif';

        switch(i) {
            case 0:
                document.h0.src = img_url;
                break;
            case 1:
                document.h1.src = img_url;
        }
    }

    for (i = 0; i < mins.length; i++) {
        char = mins.charAt(i); 
        img_url = url + '/' + char + '.gif';

        switch(i) {
            case 0:
                document.m0.src = img_url;
                break;
            case 1:
                document.m1.src = img_url;
        }
    }

    for (i = 0; i < secs.length; i++) {
        char = secs.charAt(i); 
        img_url = url + '/' + char + '.gif';

        switch(i) {
            case 0:
                document.s0.src = img_url;
                break;
            case 1:
                document.s1.src = img_url;
        }
    }
}


/************************************************************************
 *  Function to open a custom webcam slideshow window.          *
 ************************************************************************/
function webcamCustomSlideshow(cnum,sdate,stime,edate,etime) {
    var n,f,u;

    n = 'sncwebcam';
    f = 'resizable=no,width=440,height=300';
    u = 'http://www.snc.edu/cgi-bin/webcam/camslideshow.cgi' + '?cnum=' + cnum + '&sdate=' + sdate + '&edate=' + edate + '&stime=' + stime + '&etime=' + etime;

    window.open(u,n,f);

    // http://www.snc.edu/cgi-bin/webcam/camslideshow.cgi?cnum=005f&o=&sdate=01/11/2012&edate=01/11/2012&stime=07:50&etime=14:20
}


/************************************************************************
 *  Function to open up the 360 Stay Safe program in a window.      *
 ************************************************************************/
function staySafe360() {
    var n,f,u;

    n = 'staysafe360';
    f = 'resizable=yes,width=860,height=540';
    u = 'https://www.snc.edu/campussafety/login/360staysafe/';

    window.open(u,n,f);
}


/************************************************************************
 *  Function to open up the campus tour in a window.            *
 ************************************************************************/
function tourWindow(mode) {
    var n,f,u,w,h;

    n = 'snctour';
    var dims = new Array(2);

    // **************************************************************
    if (mode == 'full') {
        f = 'resizable=yes,width=800,height=600';
        u = 'http://tour.snc.edu/tourfiles/flash/index_fs.html';
    } else if (mode == 'dynamic') {
        dims = getDims();
        w = dims[0];
        w = Math.floor(dims[0] * .8);   // make width 80% of window size
        h = Math.floor(w * .75);    // make height 75% of width
        f = 'resizable=yes,width=' + w + ',height=' + h;
        u = 'http://tour.snc.edu/tourfiles/flash/index.html';
    } else {
        f = 'resizable=yes,width=800,height=600';
        u = 'http://tour.snc.edu/tourfiles/flash/index.html';
    }

    // **************************************************************
    window.open(u,n,f);
}


/************************************************************************
 *  Function to open up the live stats (sports) in a window.        *
 ************************************************************************/
function livestatsWindow() {
    var u = 'http://www.snc.edu/athletics/teamfiles/livestats/xlive.htm';
    var n = 'snclivestats';
    var f = 'toolbar=no,width=780,height=540';
    window.open(u,n,f);
}


/************************************************************************
 *  Function to open up a video in a window.                *
 ************************************************************************/
function videoWindow(flvurl,w,h) {
    // **************************************************************
    if (w == undefined) w = 340;
    if (h == undefined) h = 280;

    // **************************************************************
    var u = 'http://www.snc.edu/cgi-bin/webdev/videowindow.cgi?flv=' + flvurl;
    var n = 'sncvideo';
    var f = 'toolbar=no,width=' + w + ',height=' + h;
    window.open(u,n,f);
}


/************************************************************************
 *  Function to open up a video in a window.                *
 ************************************************************************/
function videoConfig(id,w,h) {
    // **************************************************************
    if (w == undefined) w = 300;
    if (h == undefined) h = 300;

    // **************************************************************
    var u = 'http://www.snc.edu/cgi-bin/webdev/video.cgi?id=' + id;
    var n = 'sncvideo';
    var f = 'toolbar=no,width=' + w + ',height=' + h;
    window.open(u,n,f);
}


/************************************************************************
 *  Function to get the dimensions of the current browser window.   *
 ************************************************************************/
function getDims() {
    var myWidth = 0, myHeight = 0;

    if( typeof( window.innerWidth ) == 'number' ) {
        // Non-IE
        myWidth = window.innerWidth; myHeight = window.innerHeight;
    }

    else if( document.documentElement && ( document.documentElement.clientWidth ||document.documentElement.clientHeight ) ) {
        // IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth; myHeight = document.documentElement.clientHeight;
    }

    else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        // IE 4 compatible
        myWidth = document.body.clientWidth; myHeight = document.body.clientHeight;
    }

    var result = new Array(myWidth,myHeight);

    return(result);
}


/************************************************************************
 *  Function to determine if this user's browser has the IE bug.    *
 *  http://support.microsoft.com/default.aspx/kb/927917     *
 *  http://www.javascriptkit.com/javatutors/navigator.shtml     *
 ************************************************************************/
function ieBugBrowser() {
    var bugexists,ieversion;

    bugexists = 0;

    // **************************************************************
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
        var ieversion=new Number(RegExp.$1);
        if (ieversion<8) bugexists = 1;
    }

    // **************************************************************
    return bugexists;
}


/************************************************************************
 *  Function to share a URL on Facebook.                *
 ************************************************************************/
function share_fb() {
    var u,t,link;

    u   = location.href;
    t   = document.title;
    link    = 'http://www.facebook.com/sharer.php?u=' + encodeURIComponent(u) + '&t=' + encodeURIComponent(t);

    window.open(link,'snc','toolbar=0,status=0,width=626,height=436');
    return false;
}

/************************************************************************
 *  Credit card payment functions.                  *
 ************************************************************************/
function paymentMethod(v) {
    for (i = 0; i < document.theform.cc_type.options.length; i++) {
        val = document.theform.cc_type.options[i].value;
        if (val == v) {
            document.theform.cc_type.selectedIndex = i;
        }
    }
}

/************************************************************************
 *  Adjust the height of an iframe based on its contents.       *
 ************************************************************************/
function changeFrameHeight(theid) {
    document.getElementById(theid).height = document.getElementById(theid).contentWindow.document.body.scrollHeight;
}

