
function closePopup( afterNmins ) {
    
    alert( "closing popup" );
    setTimeout( 'window.self.close()', afterNmins*60000 );
}


function openBareWin(url2Load, width, height)
{
		if ( width == null) width =700;
		if ( height == null ) height=450;	
		x = (screen.Width - width  - 10)/2; 
		y = (screen.Height- height - 30)/2; 
		// Open window using vars, note use of ScreenX/ScreenY for Netscape or variants as well as IE
		window.open( url2Load, "", "dependent=no,directories=no,location=no,hotkeys=no,menubar=no,resizable=yes,toolbar=no,scrollbars=yes,width=" + width + ",height=" + height + ",resizable=yes,left=" + x + " ,top=" + y + ",screenX=" + x + ",screenY=" + y);
}


var submitCount = 0;

function checksubmitcount(form)
{
    submitCount++;
    if (submitCount == 1) {
        form.submit();
        return true;
    } else {
        alert('You have already submitted this form; please wait for it to be processed');
        return false;
    }
}


function setDisplay(name, mode)
{
    if ( mode == 'inline' ) mode = '';  // CSS workaround
  
    var elems = document.getElementsByName(name);
    for (j = 0; j < elems.length; j++) {
        elems[j].style.display = mode;
    }
}



function stringChoice(doc, name, arr, def, size, onchange)
{
    var i;

    doc.write('<select name ="', name, '" id="', name, '"' );
    if (size != -1) {
        doc.write(' size="', size, '"');
    }
    if (onchange != "") {
        doc.write(" onchange='", onchange, "'");
    }
    doc.writeln('>');
    for (i = 0; i < arr.length; i++) {
        doc.write('<option ');
        if (arr[i] == def) {
            doc.write('selected ');
        }
        doc.writeln('value="', toHTML(arr[i]), '">', arr[i]);
    }
    doc.writeln('</select>');
}

function changeStringChoice(c, arr, def)
{
    var found = false;
    c.length = 0;
    c.selectedIndex = 0;
    for (i = 0; i < arr.length; i++) {
        var no = new Option();
        no.value = arr[i];
        no.text = no.value;
        c.options[c.options.length] = no;
        if (arr[i] == def) {
            found = true;
            c.selectedIndex = i;
        }
    }
    if (!found) {
        // Default not in list---select first element
        c.selectedIndex = 0;
    }
}



function getChoice(c)
{
    if ( c == null || c.options == null ) return 0;
    return c.options[c.selectedIndex].value
}


function getDefChoice(frm, field, def)
{
    var elem = findField(frm, field);
    if (elem == 0) {
        return def;
    }
    return elem.options[elem.selectedIndex].value
}


function numericChoice(doc, name, min, max, def, size, onchange)
{
    numericChoice(doc, name, min, max, def, size, onchange, false)
}

function numericChoice(doc, name, min, max, def, size, onchange, twoDigitMin)
{
    var arr = new Array(max - min + 1);
    var i;
    var val;

    for (i = 0; i < arr.length; i++) {
        val = min + i;   
        if (twoDigitMin && val >= 0 && val <= 9) {
            arr[i] = "0" + val;
        } else {
            arr[i] = val;
        }
    }
    if (twoDigitMin && def.length == 1) {
        def = "0" + def;
    }
    stringChoice(doc, name, arr, def, size, onchange);
}

function changeIntChoice(c, min, max, def)
{
    changeIntChoice(c, min, max, def, false)
}

function changeIntChoice(c, min, max, def, twoDigitMin)
{
    var arr = new Array(max - min + 1);
    var i;

    if (def < min) {
        def = min;
    }
    if (def > max) {
        def = max;
    }
    for (i = 0; i < arr.length; i++) {
        val = min + i;   
        if (twoDigitMin && val >= 0 && val <= 9) {
            arr[i] = "0" + val;
        } else {
            arr[i] = val;
        }
    }
    if (twoDigitMin && def >= 0 && def <= 9) {
        def = "0" + def;
    }
    changeStringChoice(c, arr, def);
}


function getIntChoice(c)
{
    var num = new Number(c.options[c.selectedIndex].value);
    return num.valueOf();
}


function getDefIntChoice(frm, field, def)
{
    var elem = findField(frm, field);
    if (elem == 0) {
        return def;
    }
    return getIntChoice(elem);
}


function getMaxIntChoice(c)
{
    var num = new Number(c.options[c.length - 1].value);
    return num.valueOf();
}


function makeTextField(doc, name, maxlength, size, val)
{
    doc.write('<input type="text" name="', name, '" id="', name, '"');
    if (maxlength != -1) {
        doc.write(' maxlength=', maxlength);
    }
    if (size != -1) {
        doc.write(' size=', size);
    }
    if (val != "") {
        doc.write(' value="', val, '"');
    }  
    doc.writeln('>');
}

function getDefValue(frm, field, def)
{
    var elem = findField(frm, field);
    if (elem == 0) {
        return def;
    }

    // A new String is returned to ensure that an empty value is not
    // passed back as a null string (was causing null pointer exception in
    // an applet.
    return new String(elem.value);
}


function makeTextArea(doc, name, rows, cols, val, wrap)
{
    doc.write('<textarea name="', name, '" id="', name, '"');
    if (rows != -1) {
        doc.write(' rows=', rows);
    }
    if (cols != -1) {
        doc.write(' cols=', cols);
    }
    if (wrap) {
        doc.write(' wrap');
    }
    doc.writeln('>');
    if (val != "") {
        doc.write(toHTML(val));
    }  
    doc.writeln('</textarea>');
}

function makeCheckBox(doc, name, value, checked, onclick)
{
    doc.write('<input type="checkbox" name="', name, '" id="', name, '" value="',  value, '"');
    if (checked) {
        doc.write(' checked="checked"');
    }
    if (onclick != "") {
        doc.write(" onclick='", onclick, "'");
    }
    doc.write('/>');
}


function fieldInForm(frm, field )
{
    return findField(frm, field ) != 0;
}


function findField(frm, field )
{

	var el = document.getElementById( field );
	if ( el != null ) {
	   return el;
	}

    return 0;
}


function checkBlank(field, msg, fieldvalue)
{
    if (field.value == "") {
        alert(msg);
        field.value = fieldvalue;
        field.select();
        field.focus();
        return true;
    }
    return false;
}


function printButton(script, label)
{
    return '<A HREF="javascript:' + script + '">' + label + '</A>';
// <button type="button" onclick='bookit();'>Book it!</button>-->
}


function printImg(name, where, toplev, alt, alignment)
{
    var str = '<img name=' + name + ' src="' + where +
            '" onError="document.' + name + '.src=' + "'" + 
            toplev.imageDir + "dot.gif'" + ';"';
    if (alt != "") {
        str += ' alt="' + alt + '"';
    }
    if (alignment != "") {
        str += ' align=' + alignment;
    }
    str += ' border=0>';
    return str;
}


// Converts a string so that it can be included in HTML.
// This amounts to replacing the four characters with significance
// to HTML with their special symbols.
function toHTML(str)
{
    s = new String(str);
    s = s.replace(/&/g, '&amp;');   // Must be first!
    s = s.replace(/</g, '&lt;');
    s = s.replace(/>/g, '&gt;');
    s = s.replace(/"/g, '&quot;');
    return s;
}

// Rather un-general function for converting an int 
// representing a credit card expiry month or year
// into a two digit string.
function zeropad(i)
{
    var s = "" + i;
    if (s.length < 2) {
        s = "0" + s;
    }
    return s;
}
