/*
** Webbeget 1.0 Javascript
** Robb Garrioch 04/16/2006
** All rights reserved.
*/

function set_default_visual()
{
    //document.getElementById('htmlversion').style.display = 'none';
}


// Original code block by Simon Willison:
// http://simon.incutio.com/archive/2004/05/26/addLoadEvent
function addloadevent(func)
{
    var oldonload = window.onload;
    if(typeof window.onload != 'function')
        window.onload = func;
    else
    {
        window.onload = function() {
            oldonload();
            func();
        }
    }
}
addloadevent(set_default_visual);



function buildquerystring(frm)
{
    frm.onsubmit = function() {
        for(var i = 0; i < this.elements.length; i++)
        {
            if((this.elements[i].value != "") && (this.elements[i].type != "submit"))
            {
                qs += this.elements[i].name;
                qs += "=";
                qs += encodeURIComponent(this.elements[i].value);
                qs += "&";
            }
        }
        return qs;
    }
}


function writeresponse(elem, content)
{
    elem.innerHTML = content;
}

function getstyleobj(id)
{
    if(document.getElementById && document.getElementById(id))
    {
	return document.getElementById(id).style;
    }
    else if (document.all && document.all(id))
    {  
 	return document.all(id).style;
    } 
    else if (document.layers && document.layers[id])
    { 
 	return document.layers[id];
    }
    else
 	return false;
}


function display(id)
{
    var idobj = getstyleobj(id);

    if(idobj)
    {
        idobj.display = 'block';
        return true;
    }
    else
        return false;
}


function displaynone(id)
{
    var idobj = getstyleobj(id);

    if(idobj)
    {
        idobj.display = 'none';
        return true;
    }
    else
        return false;
}

function display_notify(uniqueid)
{
    // get the expansion flag determination
    eval("var exp = divexpandflag" + uniqueid + ";");

    // we want to reset the div height of the lft and rht divs
    // so get the offset (original height) of the rht div
    // and then set the lft and rht height for both

    if(exp == 0)
    {
        var id;
        id = 'lft_cell_rht' + uniqueid + '';
        var elm = document.getElementById(id);
        elm.style.height = 'auto';
        elm.style.overflow = 'visible';


        id = 'lft_cell_lft' + uniqueid + '';
        var elm2 = document.getElementById(id);
        elm2.style.height = 'auto';
        elm2.style.overflow = 'visible';

        var x = elm.offsetHeight;
        var x = x + 45;			// 45

        elm.style.height = x + "px";
        elm2.style.height = x + "px";
    }

    // set the flag that disallows height incrementation
    eval("divexpandflag" + uniqueid + " = 1;");

    display("notify" + uniqueid);
}

function displaynone_notify(uniqueid)
{
    // get the expansion flag determination
    eval("var exp = divexpandflag" + uniqueid + ";");

    // we want to reset the div height of the lft and rht divs
    // so get the offset (original height) of the rht div
    // and then set the lft and rht height for both

    if(exp == 1)
    {
        var id;
        id = 'lft_cell_rht' + uniqueid + '';
        var elm = document.getElementById(id);
        elm.style.height = 'auto';
        elm.style.overflow = 'visible';


        id = 'lft_cell_lft' + uniqueid + '';
        var elm2 = document.getElementById(id);
        elm2.style.height = 'auto';
        elm2.style.overflow = 'visible';

        var x = elm.offsetHeight;
        var x = x - 20;			// even though 45 was added, taking that much away squishes the field
        //alert("displaynone_notify x value is " + x);
        elm.style.height = x + "px";
        elm2.style.height = x + "px";
    }

    // set the flag that allows height incrementation
    eval("divexpandflag" + uniqueid + " = 0;");


    displaynone("notify" + uniqueid);
}

function open_window(page, name, width, height, top, left, center)
{
    var args
    if((parseInt(navigator.appVersion) >= 4 ) && (center != "no"))
    {
        if((center == "yes") || (center == "left"))
            left = (screen.width - width) / 2;
        if((center == "yes") || (center == "top"))
            top = (screen.height - height) / 2;
    }
    args = "width=" + width + "," + 
           "height=" + height + "," +
           "top=" + top +"," +
           "left=" + left + "," +
           "toolbar=0," +
           "location=0," +
           "directories=0," +
           "status=0," +
           "menubar=0," +
           "scrollbars=0," +
           "resizable=0"

    var winobj = window.open(page, name, args);
    winobj.focus();
}



function loadproductlist()
{
    for(t = 1; t < productlist.length; t++)
    {
        formdoc.available.options[t] = new Option();
        formdoc.available.options[t].text = productlist[t];
        formdoc.available.options[t].value = productlist[t];
    }
}



function moveselection(fromopt, toopt)
{
    var arrseloptions, selvalue, seltext, evalstr;
    var currindextracking, fromoptobj, tooptobj;

    arrseloptions = new Array();
    eval("arrseloptions = formdoc." + fromopt + ".options");
    var numoptsremoved = 0;
    maxarrind = arrseloptions.length - 1;
    maxarrindsave = maxarrind;
    var i = 0;
    var flag = 1;
    while(flag)
    {
        fromoptobj = "formdoc." + fromopt;
        tooptobj = "formdoc." + toopt;
        iadjusted = i - numoptsremoved;

        if(iadjusted < arrseloptions.length)
        {
            evalstr = "";
            eval("seltext = " + fromoptobj + ".options[" + iadjusted + "].text; ");
            eval("selvalue = " + fromoptobj + ".options[" + iadjusted + "].value; ");
            evalstr = "if((" + fromoptobj + ".options[" + iadjusted + "].selected) && " +
            "(selvalue != ''))" + 
            "{ " +
                // adds new options
                tooptobj + ".options[" + tooptobj + ".options.length] " + 
                   "= new Option('" + seltext + "', '" + selvalue + "', 0, 0); " +
                // subtracts options
                fromoptobj + ".options[" + iadjusted + "] = null; " +
                "numoptsremoved++; " +
                "maxarrind--; " +
            "}";
            //alert("i is " + i + "\niadjusted " + iadjusted + "\nmaxarrind " + maxarrind);
            eval(evalstr);
        }
        else
        {
            flag = 0;
        }
        i++
    }
}


function multimakestr(selst)
{
    var str = "";
    eval("var len = formdoc." + selst + ".length");
    for(var t = 0; t < len; t++)
    {
        eval("var s2 = formdoc." + selst + ".options[" + t + "].text");
        str = str + s2 + ",";
    }
    return str;
}

function makestr(selst)
{
    eval("var multisel = formdoc." + selst);
    var len = multisel.length
    var a = new Array();

    var opt;
    var z = 0;
    for(var x = 0; x < len; x++)
    {
        opt = multisel.options[x];
        if(opt.selected)
        {
            a[z] = opt.value;
            z++;
        }
    }
    return a.join();
}


var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autotab(input,len, e)
{
    var keyCode = (isNN) ? e.which : e.keyCode; 
    if(input.value.length >= len)
    {
        input.value = input.value.slice(0, len);
        input.form[(getIndex(input)+1) % input.form.length].focus();
    }
    function getIndex(input)
    {
        var index = -1, i = 0, found = false;
        while (i < input.form.length && index == -1)
        if (input.form[i] == input)index = i;
        else i++;
        return index;
    }
    return true;
}






function dateobj(id, monthnum, month, numofdays)
{
   this.id = id;
   this.monthnum = monthnum;
   this.month = month;
   this.numofdays = numofdays;
   return true;
}


var monthinfo = new Array();

monthinfo[0] = new dateobj(0, '01', 'January', 31);
monthinfo[1] = new dateobj(1, '02', 'February', 28);
monthinfo[2] = new dateobj(2, '03', 'March', 31);
monthinfo[3] = new dateobj(3, '04', 'April', 30);
monthinfo[4] = new dateobj(4, '05', 'May', 31);
monthinfo[5] = new dateobj(5, '06', 'June', 30);
monthinfo[6] = new dateobj(6, '07', 'July', 31);
monthinfo[7] = new dateobj(7, '08', 'August', 31);
monthinfo[8] = new dateobj(8, '09', 'September', 30);
monthinfo[9] = new dateobj(9, '10', 'October', 31);
monthinfo[10] = new dateobj(10, '11', 'November', 30);
monthinfo[11] = new dateobj(11, '12', 'December', 31);













