//
//  Global variables
//

var EditorFields = Array();
var EditorObjects = Array();


//
//  Global Functions
//

function submitForm(id)
{	
	var form = document.getElementById(id);
	if (!form.onsubmit) {
		form.onsubmit = function() { return true; }
	}
	
	if (form.onsubmit()) {
		form.submit();
	}
	return false;
}

function getWindow()
{
    if (top.content) {
        return top.content;
    } else {
        return window;
    }
}

function show(id)
{
    document.getElementById(id).style.display = 'block';
}

function hide(id)
{
    document.getElementById(id).style.display = 'none';
}

function toggle(id)
{
    if ('block' == document.getElementById(id).style.display) {
        hide(id);
    } else {
        show(id);
    }
}

function redirect(url)
{
    getWindow().location.href = url;
}

function validateEmpty(id)
{
    element = document.getElementById(id);

    if (null != element && 0 == element.value.length) {
        return false;
    }

    return true;
}

function validateCheckNumber(that)
{
    form = that.form;

    if (form.check_action.value != '0') {
        if (form.auction_check.value == '' || form.auction_check.value == '0') {
            alert('You must provide a check number!');
        } else {
            form.submit();
        }
    }

    return false;
}

function validateInvoice(that)
{
    form = that.form;

    form.submit();

    return false;
}

function selectorUpdate(hidden_id, hidden_value, output_id, output_value)
{
    source = window.opener ? window.opener.document : window.document;
    hidden = source.getElementById(hidden_id);
    output = source.getElementById(output_id);
    hidden.value = hidden_value;
    output.innerHTML = output_value;
    window.close();
    return false;
}

function addEditor(id, height)
{
    index = EditorFields.push(id) - 1;

    EditorObjects[index] = new FCKeditor(EditorFields[index]);
    EditorObjects[index].Height = height;
}