/**
 * Called to process submits for various forms.
 *
 * @param frm The form we're submitting.
 * @param func The reason we're doing a submit
 *
 * @return boolean whether to run the query or not
 */
function submit_form(frm, func)
{
    if (frm)
    {
        frm.func.value = func;
        return true;
    }
}

/**
 * contractors_previous() decrements the current row by one and returns true
 * for submittal.  If it can't be decremented the user is notified.
 */
function contractors_previous(frm)
{
    if (frm)
    {
        frm.func.value = "previous";
        var row = frm.currow.value - 1;

        if (row > 1)
        {
            frm.currow.value = row;
            return true;
        }
        else
        {
            alert("At beginning!");
        }
    }

    return false;
}

/**
 * contractors_next() increments the current row by one and returns true
 * for submittal.  If it can't be incremented the user is notified.
 */
function contractors_next(frm)
{
    if (frm)
    {
        frm.func.value = "next";
        var row = frm.currow.value;
        row++;
        
        if ((row) < frm.lastrow.value)
        {
	        frm.currow.value = row;
 	        return true;
        }
        else
            alert("At end!");
    }

    return false;
}

/**
 * lpgas_previous() decrements the current row by one and returns true
 * for submittal.  If it can't be decremented the user is notified.
 */
function lpgas_previous(frm)
{
    if (frm)
    {
        frm.func.value = "previous";
        var row = frm.currow.value - 1;

        if (row > 1)
        {
            frm.currow.value = row;
            return true;
        }
        else
        {
            alert("At beginning!");
        }
    }

    return false;
}

/**
 * lpgas_next() increments the current row by one and returns true
 * for submittal.  If it can't be incremented the user is notified.
 */
function lpgas_next(frm)
{
    if (frm)
    {
        frm.func.value = "next";
        var row = frm.currow.value;
        row++;
        
        if ((row) < frm.lastrow.value)
        {
	        frm.currow.value = row;
 	        return true;
        }
        else
            alert("At end!");
    }

    return false;
}

/**
 * Popup pops a window up.
 */
function popopen(url, name)
{
    var newWin=window.open(url,name,"scrollbars,resizable=yes,left=0,top=0,height="+(screen.height-130)+",width=800");
    newWin.focus();
}

/**
 * Link to a URL
 */
function linkto(url)
{
    window.location=url;
}

/**
 * Clear all items on the search form to their empty values.
 */
function clear_search_form(f)
{
    for (i = 0; i < f.elements.length; i++)
    {
        if (f.elements[i].type == "text")
            f.elements[i].value = "";
        else if (f.elements[i].type == "select-one")
            f.elements[i].selectedIndex = 0;
    }
}

/**
 * Clear qp search params.
 */
function clear_qp_search_params(f)
{
	f.qpLastName.value = "";
	f.qpFirstName.value = "";
}

/**
 * Clear contractor search params.
 */
function clear_contractor_search_params(f)
{
	f.name.value = "";
	f.licenseNo.value = "";
}

/**
 * Lookup the value of one element and if it's equal the value passed,
 * enable another form element.  Otherwise, disable the other form element.
 * If the other form element is disabled, we also clear it's value.
 */
function lookupState(fe1, val, fe2)
{
	var str = "";
	var elem = fe1.value;

	for (var i = 0; i < elem.length; i++)
	{
		if (elem.charAt(i) != ' ')
			str = str + elem.charAt(i);
	}

	if (str == val)
	{
		fe2.disabled = false;
	}
	else
	{
		fe2.value = "";
		fe2.disabled = true;
	}
}

function closeAll()
{
	var view = window.open('','view','width=1,height=1,scrollbars=no,left=5000,top=5000');
	view.close();
	view = window.open('','qpview','width=1,height=1,scrollbars=no,left=5000,top=5000');
	view.close();
}