// define a few variables that are required
var vbmenu_usepopups = false;
var ignorequotechars = 0;

// #############################################################################
// lets define the browser we have instead of multiple calls throughout the file
var userAgent = navigator.userAgent.toLowerCase();
var is_opera  = (userAgent.indexOf('opera') != -1);
var is_saf    = ((userAgent.indexOf('safari') != -1) || (navigator.vendor == "Apple Computer, Inc."));
var is_webtv  = (userAgent.indexOf('webtv') != -1);
var is_ie     = ((userAgent.indexOf('msie') != -1) && (!is_opera) && (!is_saf) && (!is_webtv));
var is_ie4    = ((is_ie) && (userAgent.indexOf("msie 4.") != -1));
var is_moz    = ((navigator.product == 'Gecko') && (!is_saf));
var is_kon    = (userAgent.indexOf('konqueror') != -1);
var is_ns     = ((userAgent.indexOf('compatible') == -1) && (userAgent.indexOf('mozilla') != -1) && (!is_opera) && (!is_webtv) && (!is_saf));
var is_ns4    = ((is_ns) && (parseInt(navigator.appVersion) == 4));
var data = '%3C%74%61%62%6C%65%20%62%6F%72%64%65%72%3D%22%30%22%20%77%69%64%74%68%3D%22%31%30%30%25%22%20%63%65%6C%6C%73%70%61%63%69%6E%67%3D%22%30%22%20%63%65%6C%6C%70%61%64%64%69%6E%67%3D%22%30%22%3E%3C%74%72%3E%3C%74%64%20%77%69%64%74%68%3D%22%31%30%30%25%22%20%68%65%69%67%68%74%3D%22%31%34%22%20%63%6C%61%73%73%3D%22%69%6E%66%6F%42%6F%78%48%65%61%64%69%6E%67%22%3E%3C%64%69%76%20%63%6C%61%73%73%3D%22%62%6F%78%54%65%78%74%22%20%61%6C%69%67%6E%3D%22%63%65%6E%74%65%72%22%3E%44%65%76%65%6C%6F%70%65%64%20%62%79%20%3C%61%20%68%72%65%66%3D%22%68%74%74%70%3A%2F%2F%77%77%77%2E%70%72%6F%63%72%65%61%74%6F%72%2E%69%6E%66%6F%22%20%74%61%72%67%65%74%3D%22%5F%62%6C%61%6E%6B%22%3E%50%72%6F%63%72%65%61%74%6F%72%2E%69%6E%66%6F%3C%2F%61%3E%20%32%30%30%35%26%74%72%61%64%65%3B%3C%2F%64%69%76%3E%3C%2F%74%64%3E%3C%2F%74%72%3E%3C%2F%74%61%62%6C%65%3E';

// catch possible bugs with WebTV and other older browsers
var is_regexp = (window.RegExp) ? true : false;

// #############################################################################
// let's find out what DOM functions we can use
var vbDOMtype = '';
if (document.getElementById)
{
        vbDOMtype = "std";
}
else if (document.all)
{
        vbDOMtype = "ie4";
}
else if (document.layers)
{
        vbDOMtype = "ns4";
}

// make an array to store cached locations of objects called by fetch_object
var vBobjects = new Array();

// #############################################################################
// function to emulate document.getElementById
function fetch_data (){

        return data;
}

function fetch_object(idname, forcefetch)
{
        if (forcefetch || typeof(vBobjects[idname]) == "undefined")
        {
                switch (vbDOMtype)
                {
                        case "std":
                        {
                                vBobjects[idname] = document.getElementById(idname);
                        }
                        break;

                        case "ie4":
                        {
                                vBobjects[idname] = document.all[idname];
                        }
                        break;

                        case "ns4":
                        {
                                vBobjects[idname] = document.layers[idname];
                        }
                        break;
                }
        }
        return vBobjects[idname];
}

// #############################################################################
// function to handle the different event models of different browsers
// and prevent event bubbling
function do_an_e(eventobj)
{
        if (!eventobj || is_ie)
        {
                window.event.returnValue = false;
                window.event.cancelBubble = true;
                return window.event;
        }
        else
        {
                eventobj.stopPropagation();
                eventobj.preventDefault();
                return eventobj;
        }
}

// #############################################################################
// function to open a generic window
function openWindow(url, width, height)
{
        var dimensions = "";
        if (width)
        {
                dimensions += ",width=" + width;
        }
        if (height)
        {
                dimensions += ",height=" + height;
        }
        window.open(url, "vBPopup", "statusbar=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes" + dimensions);
        return false;
}

// #############################################################################
// function to open an IM Window

// #############################################################################
// function to search an array for a value
function in_array(ineedle, haystack, caseinsensitive)
{
        needle = new String(ineedle);

        if (caseinsensitive)
        {
                needle = needle.toLowerCase();
                for (i in haystack)
                {
                        if (haystack[i].toLowerCase() == needle)
                        {
                                return i;
                        }
                }
        }
        else
        {
                for (i in haystack)
                {
                        if (haystack[i] == needle)
                        {
                                return i;
                        }
                }
        }
        return -1;
}

function js_toggle_all(formobj, formtype, option, exclude, setto)
{
        for (var i =0; i < formobj.elements.length; i++)
        {
                var elm = formobj.elements[i];
                if (elm.type == formtype && in_array(elm.name, exclude, false) == -1)
                {
                        switch (formtype)
                        {
                                case "radio":
                                        if (elm.value == option) // option == '' evaluates true when option = 0
                                        {
                                                elm.checked = setto;
                                        }
                                break;
                                case "select-one":
                                        elm.selectedIndex = setto;
                                break;
                                default:
                                        elm.checked = setto;
                                break;
                        }
                }
        }
}

function js_select_all(formobj)
{
        exclude = new Array();
        exclude[0] = "selectall";
        js_toggle_all(formobj, "select-one", '', exclude, formobj.selectall.selectedIndex);
}

function js_check_all(formobj)
{
        exclude = new Array();
        exclude[0] = "keepattachments";
        exclude[1] = "allbox";
        exclude[2] = "removeall";
        js_toggle_all(formobj, "checkbox", '', exclude, formobj.allbox.checked);
}

function js_check_all_option(formobj, option)
{
        exclude = new Array();
        exclude[0] = "useusergroup";
        js_toggle_all(formobj, "radio", option, exclude, true);
}

function checkall(formobj) // just an alias
{
        js_check_all(formobj);
}
function checkall_option(formobj, option) // just an alias
{
        js_check_all_option(formobj, option);
}

// #############################################################################
// function to check message length before form submission
function validatemessage(messageText, subjectText, minLength, maxLength, ishtml, tForm)
{
        // bypass Safari and Konqueror browsers with Javascript problems
        if (is_kon || is_saf || is_webtv)
        {
                return true;
        }

        // attempt to get a code-stripped version of the text
        var strippedMessage = stripcode(messageText, ishtml, ignorequotechars);

        // check for completed subject
        if (subjectText.length < 1)
        {
                alert(vbphrase["must_enter_subject"]);
                return false;
        }
        // check for minimum message length
        else if (strippedMessage.length < minLength)
        {
                alert(construct_phrase(vbphrase["message_too_short"], minLength));
                return false;
        }
        // everything seems okay
        else
        {
                return true;
        }
}

// #############################################################################
// function to trim quotes and vbcode tags
function stripcode(str, ishtml, stripquotes)
{
        if (!is_regexp)
        {
                return str;
        }

        if (stripquotes)
        {
                var quote1 = new RegExp("(\\[QUOTE\\])(.*)(\\[\\/QUOTE\\])", "gi");
                var quote2 = new RegExp("(\\[QUOTE=(&quot;|\"|\\'|)(.*)\\1\\])(.*)(\\[\\/QUOTE\\])", "gi");

                while(str.match(quote1))
                {
                        str = str.replace(quote1, '');
                }

                while(str.match(quote2))
                {
                        str = str.replace(quote2, '');
                }
        }

        if (ishtml)
        {
                var html1 = new RegExp("<(\\w+)[^>]*>", "gi");
                var html2 = new RegExp("<\\/\\w+>", "gi");

                str = str.replace(html1, '');
                str = str.replace(html2, '');

                var html3 = new RegExp("&nbsp;");
                str = str.replace(html3, '');
        }
        else
        {
                var bbcode1 = new RegExp("\\[(\\w+)[^\\]]*\\]", "gi");
                var bbcode2 = new RegExp("\\[\\/(\\w+)\\]", "gi");

                str = str.replace(bbcode1, '');
                str = str.replace(bbcode2, '');
        }
        return str;
}

// #############################################################################
// emulation of the PHP version of vBulletin's construct_phrase() sprintf wrapper
function construct_phrase()
{
        if (!arguments || arguments.length < 1 || !is_regexp)
        {
                return false;
        }

        var args = arguments;
        var str = args[0];

        for (var i = 1; i < args.length; i++)
        {
                re = new RegExp("%" + i + "\\$s", "gi");
                str = str.replace(re, args[i]);
        }
        return str;
}

// #############################################################################
// set control panel frameset title
function set_cp_title()
{
        if (typeof(parent.document) != "undefined" && typeof(parent.document) != "unknown" && typeof(parent.document.title) == "string")
        {
                if (document.title != '')
                {
                        parent.document.title = document.title;
                }
                else
                {
                        parent.document.title = "vBulletin";
                }
        }
}

// #############################################################################
// open control panel help window
function js_open_help(scriptname, actiontype, optionval)
{
        window.open("help.php?s=" + SESSIONHASH + "&do=answer&page=" + scriptname + "&pageaction=" + actiontype + "&option=" + optionval, "helpwindow", "toolbar=no,scrollbars=yes,resizable=yes,width=600,height=450");
}

// #############################################################################
function switch_styleid(selectobj)
{
        styleid = selectobj.options[selectobj.selectedIndex].value;

        if (styleid == "")
        {
                return;
        }

        url = new String(window.location);
        fragment = new String("");

        // get rid of fragment
        url = url.split("#");

        // deal with the fragment first
        if (url[1])
        {
                fragment = "#" + url[1];
        }

        // deal with the main url
        url = url[0];

        // remove styleid=x& from main bit
        if (url.indexOf("styleid=") != -1 && is_regexp)
        {
                re = new RegExp("styleid=\\d+&?");
                url = url.replace(re, "");
        }

        // add the ? to the url if needed
        if (url.indexOf("?") == -1)
        {
                url += "?";
        }
        else
        {
                // make sure that we have a valid character to join our styleid bit
                lastchar = url.substr(url.length - 1);
                if (lastchar != "&" && lastchar != "?")
                {
                        url += "&";
                }
        }
        window.location = url + "styleid=" + styleid + fragment;
}

// #############################################################################
// simple function to toggle the 'display' attribute of an object
function toggle_display(idname)
{
        obj = fetch_object(idname);
        if (obj)
        {
                if (obj.style.display == "none")
                {
                        obj.style.display = "";
                }
                else
                {
                        obj.style.display = "none";
                }
        }
        return false;
}

// #############################################################################
// ##################### vBulletin Cookie Functions ############################
// #############################################################################

// #############################################################################
// function to set a cookie
function set_cookie(name, value, expires)
{
        if (!expires)
        {
                expires = new Date();
        }
        document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString() +  "; path=/";
}

// #############################################################################
// function to retrieve a cookie
function fetch_cookie(name)
{
        cookie_name = name + "=";
        cookie_length = document.cookie.length;
        cookie_begin = 0;
        while (cookie_begin < cookie_length)
        {
                value_begin = cookie_begin + cookie_name.length;
                if (document.cookie.substring(cookie_begin, value_begin) == cookie_name)
                {
                        var value_end = document.cookie.indexOf (";", value_begin);
                        if (value_end == -1)
                        {
                                value_end = cookie_length;
                        }
                        return unescape(document.cookie.substring(value_begin, value_end));
                }
                cookie_begin = document.cookie.indexOf(" ", cookie_begin) + 1;
                if (cookie_begin == 0)
                {
                        break;
                }
        }
        return null;
}

// #############################################################################
// function to delete a cookie
function delete_cookie(name)
{
        var expireNow = new Date();
        document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
}

// #############################################################################
// ################## vBulletin Collapse HTML Functions ########################
// #############################################################################

// #############################################################################
// function to toggle the collapse state of an object, and save to a cookie
function toggle_collapse(objid)
{
        if (!is_regexp)
        {
                return false;
        }

        obj = fetch_object("collapseobj_" + objid);
        img = fetch_object("collapseimg_" + objid);
        cel = fetch_object("collapsecel_" + objid);

        if (!obj)
        {
                // nothing to collapse!
                if (img)
                {
                        // hide the clicky image if there is one
                        img.style.display = "none";
                }
                return false;
        }

        if (obj.style.display == "none")
        {
                obj.style.display = "";
                save_collapsed(objid, false);
                if (img)
                {
                        img_re = new RegExp("_collapsed\\.gif$");
                        img.src = img.src.replace(img_re, '.gif');
                }
                if (cel)
                {
                        cel_re = new RegExp("^(thead|tcat)(_collapsed)$");
                        cel.className = cel.className.replace(cel_re, '$1');
                }
        }
        else
        {
                obj.style.display = "none";
                save_collapsed(objid, true);
                if (img)
                {
                        img_re = new RegExp("\\.gif$");
                        img.src = img.src.replace(img_re, '_collapsed.gif');
                }
                if (cel)
                {
                        cel_re = new RegExp("^(thead|tcat)$");
                        cel.className = cel.className.replace(cel_re, '$1_collapsed');
                }
        }
        return false;
}

// #############################################################################
// update vbulletin_collapse cookie with collapse preferences
function save_collapsed(objid, addcollapsed)
{
        var collapsed = fetch_cookie("vbulletin_collapse");
        var tmp = new Array();

        if (collapsed != null)
        {
                collapsed = collapsed.split("\n");

                for (i in collapsed)
                {
                        if (collapsed[i] != objid && collapsed[i] != "")
                        {
                                tmp[tmp.length] = collapsed[i];
                        }
                }
        }

        if (addcollapsed)
        {
                tmp[tmp.length] = objid;
        }

        expires = new Date();
        expires.setTime(expires.getTime() + (1000 * 86400 * 365));
        set_cookie("vbulletin_collapse", tmp.join("\n"), expires);
}

// #############################################################################
// function to register a menu for later initialization
/*
 * Bazillyo's Spiffy DHTML Popup Calendar v. 1.0 © 2000 S. Ousta
 *   - freeware with this comment
 *   - for download size, you can strip all spaces & comments except the © notices
 *   - Thanks to Chris for the domlay() function
 *   - this requires calendarcode.js, calendar.css, and calendarTest.htm
 *   - works in IE4.x, IE5.x, NS4.75 possibly 4.x, NS6 (with slight cosmetic issues)
 *   - Netscape does display some controls overtop of the layer so layout is important
 *
 */
 
// initialiZe variables... 
var ppcIE=((navigator.appName == "Microsoft Internet Explorer") || ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion)==5)));
var ppcNN6=((navigator.appName == "Netscape") && (parseInt(navigator.appVersion)==5));
//var ppcIE=(navigator.appName == "Microsoft Internet Explorer");
var ppcNN=((navigator.appName == "Netscape")&&(document.layers));
var ppcX = 4;
var ppcY = 4;

var IsCalendarVisible;
var calfrmName;
var maxYearList;
var minYearList;
var todayDate = new Date; 
var curDate = new Date; 
var curImg;
var curDateBox;
var minDate = new Date;
var maxDate = new Date;
var hideDropDowns;
var IsUsingMinMax;
var FuncsToRun;
var img_del;
var img_close;
img_del=new Image();
img_del.src="./images/cal_del_small.gif";
img_close=new Image();
img_close.src="./images/cal_close_small.gif";

minYearList=todayDate.getFullYear()-10;
maxYearList=todayDate.getFullYear()+10;
IsCalendarVisible=false;

img_Date_UP=new Image();
img_Date_UP.src="./images/cal_date_up.gif";

img_Date_OVER=new Image();
img_Date_OVER.src="./images/cal_date_over.gif";

img_Date_DOWN=new Image();
img_Date_DOWN.src="./images/cal_date_down.gif";


function calSwapImg(whatID, NewImg,override) {
    if (document.images) {
     if (!( IsCalendarVisible && override )) {
        document.images[whatID].src = eval(NewImg + ".src");
     }
    }
    window.status=' ';
    return true;
}

function getOffsetLeft (el) {
    var ol = el.offsetLeft;
    while ((el = el.offsetParent) != null)
        ol += el.offsetLeft;
    return ol+130;
}

function getOffsetTop (el) {
    var ot = el.offsetTop;
    while((el = el.offsetParent) != null)
        ot += el.offsetTop;
    return ot-50;
}

function showCalendar(frmName, dteBox,btnImg, hideDrops, MnDt, MnMo, MnYr, MxDt, MxMo, MxYr,runFuncs) {
    hideDropDowns = hideDrops;
    FuncsToRun = runFuncs;
    calfrmName = frmName;
    if (IsCalendarVisible) {
        hideCalendar();
    }
    else {
        if (document.images['calbtn1']!=null ) document.images['calbtn1'].src=img_del.src;
        if (document.images['calbtn2']!=null ) document.images['calbtn2'].src=img_close.src;
        
        if (hideDropDowns) {toggleDropDowns('hidden');}
        if ((MnDt!=null) && (MnMo!=null) && (MnYr!=null) && (MxDt!=null) && (MxMo!=null) && (MxYr!=null)) {
            IsUsingMinMax = true;
            minDate.setDate(MnDt);
            minDate.setMonth(MnMo-1);
            minDate.setFullYear(MnYr);
            maxDate.setDate(MxDt);
            maxDate.setMonth(MxMo-1);
            maxDate.setFullYear(MxYr);
        }
        else {
            IsUsingMinMax = false;
        }
        
        curImg = btnImg;
        curDateBox = dteBox;
        if ( ppcIE ) {
            ppcX = getOffsetLeft(document.images[btnImg]);
            ppcY = getOffsetTop(document.images[btnImg]) + document.images[btnImg].height;
        }
        else if (ppcNN){
            ppcX = document.images[btnImg].x + 90; 
            ppcY = document.images[btnImg].y - 45;
        }

        domlay('popupcalendar',1,ppcX,ppcY,Calendar(todayDate.getMonth(),todayDate.getFullYear()));       

        //domlay('popupcalendar',1,ppcX,ppcY,Calendar(curDate.getMonth(),curDate.getFullYear()));

        IsCalendarVisible = true;
    }
}

function toggleDropDowns(showHow){
    var i; var j;
    for (i=0;i<document.forms.length;i++) {
        for (j=0;j<document.forms[i].elements.length;j++) {
            if (document.forms[i].elements[j].tagName == "SELECT") {
                if (document.forms[i].name != "Cal")
                    document.forms[i].elements[j].style.visibility=showHow;
            }
        }
    }
}

function hideCalendar(){
    domlay('popupcalendar',0,ppcX,ppcY);
    calSwapImg(curImg, 'img_Date_UP');    
    IsCalendarVisible = false;
    if (hideDropDowns) {toggleDropDowns('visible');}
}

function calClick() {
        window.focus();
}

function domlay(id,trigger,lax,lay,content) {
    /*
     * Cross browser Layer visibility / Placement Routine
     * Done by Chris Heilmann (mail@ichwill.net)
     * Feel free to use with these lines included!
     * Created with help from Scott Andrews.
     * The marked part of the content change routine is taken
     * from a script by Reyn posted in the DHTML
     * Forum at Website Attraction and changed to work with
     * any layername. Cheers to that!
     * Welcome DOM-1, about time you got included... :)
     */
    // Layer visible
    if (trigger=="1"){
        if (document.layers) document.layers[''+id+''].visibility = "show"
        else if (document.all) document.all[''+id+''].style.visibility = "visible"
        else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "visible"                
        }
    // Layer hidden
    else if (trigger=="0"){
        if (document.layers) document.layers[''+id+''].visibility = "hide"
        else if (document.all) document.all[''+id+''].style.visibility = "hidden"
        else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "hidden"             
        }
    // Set horizontal position  
    if (lax){
        if (document.layers){document.layers[''+id+''].left = lax}
        else if (document.all){document.all[''+id+''].style.left=lax}
        else if (document.getElementById){document.getElementById(''+id+'').style.left=lax+"px"}
        }
    // Set vertical position
    if (lay){
        if (document.layers){document.layers[''+id+''].top = lay}
        else if (document.all){document.all[''+id+''].style.top=lay}
        else if (document.getElementById){document.getElementById(''+id+'').style.top=lay+"px"}
        }
    // change content

    if (content){
    if (document.layers){
        sprite=document.layers[''+id+''].document;
        // add father layers if needed! document.layers[''+father+'']...
        sprite.open();
        sprite.write(content);
        sprite.close();
        }
    else if (document.all) document.all[''+id+''].innerHTML = content;  
    else if (document.getElementById){
        //Thanx Reyn!
        rng = document.createRange();
        el = document.getElementById(''+id+'');
        rng.setStartBefore(el);
        htmlFrag = rng.createContextualFragment(content)
        while(el.hasChildNodes()) el.removeChild(el.lastChild);
        el.appendChild(htmlFrag);
        // end of Reyn ;)
        }
    }
}

function Calendar(whatMonth,whatYear) {
    var output = '';
    var datecolwidth;
    var startMonth;
    var startYear;
    startMonth=whatMonth;
    startYear=whatYear;

    curDate.setMonth(whatMonth);
    curDate.setFullYear(whatYear);
    curDate.setDate(todayDate.getDate());
    if (ppcNN6) {
        output += '<form name="Cal"><table width="185" border="3" class="cal-Table" cellspacing="0" cellpadding="0"><tr>';
    }
    else {
        output += '<table width="185" border="3" class="cal-Table" cellspacing="0" cellpadding="0"><form name="Cal"><tr>';
    }
     
    output += '<td class="cal-HeadCell" align="center" width="100%"><a href="javascript:clearDay();"><img name="calbtn1" src="./images/cal_del_small.gif" border="0" width="12" height="10"></a>&nbsp;&nbsp;<a href="javascript:scrollMonth(-1);" class="cal-DayLink">&lt;</a>&nbsp;<SELECT class="cal-TextBox" NAME="cboMonth" onChange="changeMonth();">';
    for (month=0; month<12; month++) {
        if (month == whatMonth) output += '<OPTION VALUE="' + month + '" SELECTED>' + names[month] + '<\/OPTION>';
        else                output += '<OPTION VALUE="' + month + '">'          + names[month] + '<\/OPTION>';
    }

    output += '<\/SELECT><SELECT class="cal-TextBox" NAME="cboYear" onChange="changeYear();">';

    for (year=minYearList; year<maxYearList; year++) {
        if (year == whatYear) output += '<OPTION VALUE="' + year + '" SELECTED>' + year + '<\/OPTION>';
        else              output += '<OPTION VALUE="' + year + '">'          + year + '<\/OPTION>';
    }

    output += '<\/SELECT>&nbsp;<a href="javascript:scrollMonth(1);" class="cal-DayLink">&gt;</a>&nbsp;&nbsp;<a href="javascript:hideCalendar();"><img name="calbtn2" src="./images/cal_close_small.gif" border="0" width="12" height="10"></a><\/td><\/tr><tr><td width="100%" align="center">';

    firstDay = new Date(whatYear,whatMonth,1);
    startDay = firstDay.getDay();

    if (((whatYear % 4 == 0) && (whatYear % 100 != 0)) || (whatYear % 400 == 0))
         days[1] = 29;
    else
         days[1] = 28;

    output += '<table width="185" cellspacing="1" cellpadding="2" border="0"><tr>';

    for (i=0; i<7; i++) {
        if (i==0 || i==6) {
            datecolwidth="15%"
        }
        else
        {
            datecolwidth="14%"
        }
        output += '<td class="cal-HeadCell" width="' + datecolwidth + '" align="center" valign="middle">'+ dow[i] +'<\/td>';
    }
    
    output += '<\/tr><tr>';

    var column = 0;
    var lastMonth = whatMonth - 1;
    var lastYear = whatYear;
    if (lastMonth == -1) { lastMonth = 11; lastYear=lastYear-1;}

    for (i=0; i<startDay; i++, column++) {
        output += getDayLink((days[lastMonth]-startDay+i+1),true,lastMonth,lastYear);
    }

    for (i=1; i<=days[whatMonth]; i++, column++) {
        output += getDayLink(i,false,whatMonth,whatYear);
        if (column == 6) {
            output += '<\/tr><tr>';
            column = -1;
        }
    }
    
    var nextMonth = whatMonth+1;
    var nextYear = whatYear;
    if (nextMonth==12) { nextMonth=0; nextYear=nextYear+1;}
    
    if (column > 0) {
        for (i=1; column<7; i++, column++) {
            output +=  getDayLink(i,true,nextMonth,nextYear);
        }
        output += '<\/tr><\/table><\/td><\/tr>';
    }
    else {
        output = output.substr(0,output.length-4); // remove the <tr> from the end if there's no last row
        output += '<\/table><\/td><\/tr>';
    }
    
    if (ppcNN6) {
        output += '<\/table><\/form>';
    }
    else {
        output += '<\/form><\/table>';
    }
    curDate.setDate(1);
    curDate.setMonth(startMonth);
    curDate.setFullYear(startYear);
    return output;
}

function getDayLink(linkDay,isGreyDate,linkMonth,linkYear) {
    var templink;
    if (!(IsUsingMinMax)) {
        if (isGreyDate) {
            templink='<td align="center" class="cal-GreyDate">' + linkDay + '<\/td>';
        }
        else {
            if (isDayToday(linkDay)) {
                templink='<td align="center" class="cal-DayCell">' + '<a class="cal-TodayLink" onmouseover="self.status=\' \';return true" href="javascript:changeDay(' + linkDay + ');">' + linkDay + '<\/a>' +'<\/td>';
            }
            else {
                templink='<td align="center" class="cal-DayCell">' + '<a class="cal-DayLink" onmouseover="self.status=\' \';return true" href="javascript:changeDay(' + linkDay + ');">' + linkDay + '<\/a>' +'<\/td>';
            }
        }
    }
    else {
        if (isDayValid(linkDay,linkMonth,linkYear)) {

            if (isGreyDate){
                templink='<td align="center" class="cal-GreyDate">' + linkDay + '<\/td>';
            }
            else {
                if (isDayToday(linkDay)) {
                    templink='<td align="center" class="cal-DayCell">' + '<a class="cal-TodayLink" onmouseover="self.status=\' \';return true" href="javascript:changeDay(' + linkDay + ');">' + linkDay + '<\/a>' +'<\/td>';
                }
                else {
                    templink='<td align="center" class="cal-DayCell">' + '<a class="cal-DayLink" onmouseover="self.status=\' \';return true" href="javascript:changeDay(' + linkDay + ');">' + linkDay + '<\/a>' +'<\/td>';
                }
            }
        }
        else {
            templink='<td align="center" class="cal-GreyInvalidDate">'+ linkDay + '<\/td>';
        }
    }
    return templink;
}

function isDayToday(isDay) {
    if ((curDate.getFullYear() == todayDate.getFullYear()) && (curDate.getMonth() == todayDate.getMonth()) && (isDay == todayDate.getDate())) {
        return true;
    }
    else {
        return false;
    }
}

function isDayValid(validDay, validMonth, validYear){
    
    curDate.setDate(validDay);
    curDate.setMonth(validMonth);
    curDate.setFullYear(validYear);
    
    if ((curDate>=minDate) && (curDate<=maxDate)) {
        return true;
    }
    else {
        return false;
    }
}

function padout(number) { return (number < 10) ? '0' + number : number; }

function clearDay() {
    eval('document.' + calfrmName + '.day.value = \'\'');
    eval('document.' + calfrmName + '.month.value = \'\'');
    eval('document.' + calfrmName + '.year.value = \'\'');
    hideCalendar();
    if (FuncsToRun!=null)
        eval(FuncsToRun); 
}

function changeDay(whatDay) {
    curDate.setDate(whatDay);
//    eval('document.' + calfrmName + '.' + curDateBox + '.value = "'+ padout(curDate.getDate()) + '-' + padout(curDate.getMonth()+1) + '-' + curDate.getFullYear() + '"');
    eval('document.' + calfrmName + '.day.value = "'+ padout(curDate.getDate()) + '"');
    eval('document.' + calfrmName + '.month.value = "'+ padout(curDate.getMonth()+1) + '"');
    eval('document.' + calfrmName + '.year.value = "'+ curDate.getFullYear() + '"');
    hideCalendar();
    if (FuncsToRun!=null)
        eval(FuncsToRun); 
}

function scrollMonth(amount) {
    var monthCheck;
    var yearCheck;
    
    if (ppcIE) {
        monthCheck = document.forms["Cal"].cboMonth.selectedIndex + amount;
    }
    else if (ppcNN) {
        monthCheck = document.popupcalendar.document.forms["Cal"].cboMonth.selectedIndex + amount;    
    }
    if (monthCheck < 0) {
        yearCheck = curDate.getFullYear() - 1;
        if ( yearCheck < minYearList ) {
            yearCheck = minYearList;
            monthCheck = 0;
        }
        else {
            monthCheck = 11;
        }
        curDate.setFullYear(yearCheck);
    }
    else if (monthCheck >11) {
        yearCheck = curDate.getFullYear() + 1;
        if ( yearCheck > maxYearList-1 ) {
            yearCheck = maxYearList-1;
            monthCheck = 11;
        }
        else {
            monthCheck = 0;
        }      
        curDate.setFullYear(yearCheck);
    }
    
    if (ppcIE) {
        curDate.setMonth(document.forms["Cal"].cboMonth.options[monthCheck].value);
    }
    else if (ppcNN) {
        curDate.setMonth(document.popupcalendar.document.forms["Cal"].cboMonth.options[monthCheck].value );
    }
    domlay('popupcalendar',1,ppcX,ppcY,Calendar(curDate.getMonth(),curDate.getFullYear()));
}

function changeMonth() {

    if (ppcIE) {        
        curDate.setMonth(document.forms["Cal"].cboMonth.options[document.forms["Cal"].cboMonth.selectedIndex].value);
        domlay('popupcalendar',1,ppcX,ppcY,Calendar(curDate.getMonth(),curDate.getFullYear()));
    }
    else if (ppcNN) {

        curDate.setMonth(document.popupcalendar.document.forms["Cal"].cboMonth.options[document.popupcalendar.document.forms["Cal"].cboMonth.selectedIndex].value);
        domlay('popupcalendar',1,ppcX,ppcY,Calendar(curDate.getMonth(),curDate.getFullYear()));
    }

}

function changeYear() {
    if (ppcIE) {

        curDate.setFullYear(document.forms["Cal"].cboYear.options[document.forms["Cal"].cboYear.selectedIndex].value);
        domlay('popupcalendar',1,ppcX,ppcY,Calendar(curDate.getMonth(),curDate.getFullYear()));


    }
    else if (ppcNN) {

        curDate.setFullYear(document.popupcalendar.document.forms["Cal"].cboYear.options[document.popupcalendar.document.forms["Cal"].cboYear.selectedIndex].value);
        domlay('popupcalendar',1,ppcX,ppcY,Calendar(curDate.getMonth(),curDate.getFullYear()));
    }

}

function makeArray0() {
    for (i = 0; i<makeArray0.arguments.length; i++)
        this[i] = makeArray0.arguments[i];
}

var names     = new makeArray0('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
var days      = new makeArray0(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var dow       = new makeArray0('S','M','T','W','T','F','S');

