String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}


function view_ConfirmReport(id)
{
    if ( confirm("Are you sure you wish to report this content as offensive?"))
    {
        window.location = "/db/report/"+id+"/"
    }
}


/*

    SORT PLANE LIST

*/
function planeList_DoSort()
{
    var col = document.getElementById('sortColumn').value;
    var ord = document.getElementById('sortOrder').value;
    window.location = "/db/sort/"+col+"/"+ord+"/";
}

function planeList_ConfirmDelete(plane)
{
    window.location = "/db/delete/" + plane + "/confirm/";
}


/*

    ADD PLANE FORM

*/
var addForm_currentStep = 1;
function addForm_ShowNextStep()
{
    if (document.getElementById('editstep'+(addForm_currentStep+1)+'_div')!=null)
    {
        addForm_currentStep++;
        document.getElementById('editstep'+addForm_currentStep+'_div').style.display = "block";

        document.getElementById('editSteps').scrollTop = document.getElementById('editSteps').scrollHeight;
    }
}

function addForm_ExpandSteps()
{
    document.getElementById('editSteps').style.height = 'auto';
    document.getElementById('editStepsShowAll').style.display = 'none';
    document.getElementById('editSteps').style.overflow = 'hidden';
}

function addForm_SetError(msg)
{
    document.getElementById('editError').innerHTML = msg;
}

function addForm_Validate()
{
    var msg='';
    if (document.getElementById('title').value.trim()=='')
        msg= "You must fill in a title for this plane.";
    else if (document.getElementById('keywords').value.trim()=='')
        msg="You must fill in at least one keyword for this plane.";
    else if (document.getElementById('editstep1_details').value.trim()=='')
        msg= "You must fill in the details for at least one step.";

    if (msg=='')
        return true;
    else
        addForm_SetError(msg);
    return false;
}


/*

    EDIT PLANE FORM

*/
function editForm_Validate()
{
    var msg='';
    if (document.getElementById('title').value.trim()=='')
        msg= "You must fill in a title for this plane.";
    else if (document.getElementById('keywords').value.trim()=='')
        msg="You must fill in at least one keyword for this plane.";

    if (msg=='')
        return true;
    else
        addForm_SetError(msg);
    return false;
}
