﻿// Tilføjer tekst til et textarea
function AddText(startTag,defaultText,endTag)
{
    //var textBox=ctl00_ContentPlaceHolder1_DetailsView1_TextBoxTekst;
    with(document.getElementById("aspnetForm")) // 'form' er navnet på den form der skal gøres noget med
    {
    if (ctl00_ContentPlaceHolder1_DetailsView1_TextBoxTekst.createTextRange)
    {
        var text;        
        // 'message' er navnet paa det felt der skal skrives i, hvis du aendrer navnet, så husk at aendre det alle steder
        ctl00_ContentPlaceHolder1_DetailsView1_TextBoxTekst.focus(ctl00_ContentPlaceHolder1_DetailsView1_TextBoxTekst.caretPos); 
        ctl00_ContentPlaceHolder1_DetailsView1_TextBoxTekst.caretPos = document.selection.createRange().duplicate();
        if(ctl00_ContentPlaceHolder1_DetailsView1_TextBoxTekst.caretPos.text.length>0)
        {
            var sel = ctl00_ContentPlaceHolder1_DetailsView1_TextBoxTekst.caretPos.text;
            var fin = '';
            while(sel.substring(sel.length-1, sel.length)==' ')
            {
                sel = sel.substring(0, sel.length-1)
                fin += ' ';
            }
            ctl00_ContentPlaceHolder1_DetailsView1_TextBoxTekst.caretPos.text = startTag + sel + endTag + fin;
        }
        else
        ctl00_ContentPlaceHolder1_DetailsView1_TextBoxTekst.caretPos.text = startTag+defaultText+endTag;
    }
    else ctl00_ContentPlaceHolder1_DetailsView1_TextBoxTekst.value += startTag+defaultText+endTag;
    }
}

// Tilføjer et ekstra Uploadfelt
function addFileUploadBox()
{
    if (!document.getElementById || !document.createElement)
        return false;
		
    var uploadArea = document.getElementById ("upload-area");
	
    if (!uploadArea)
        return;

    var newLine = document.createElement ("br");
    uploadArea.appendChild (newLine);
	
    var newUploadBox = document.createElement ("input");
	
    // Set up the new input for file uploads
    newUploadBox.type = "file";
    newUploadBox.size = "60";
	
    // The new box needs a name and an ID
    if (!addFileUploadBox.lastAssignedId)
        addFileUploadBox.lastAssignedId = 100;
    
    newUploadBox.setAttribute ("id", "dynamic" + addFileUploadBox.lastAssignedId);
    newUploadBox.setAttribute ("name", "dynamic:" + addFileUploadBox.lastAssignedId);
    uploadArea.appendChild (newUploadBox);
    
    addFileUploadBox.lastAssignedId++;
}

// Checker eller UnChecker alle CheckBoxes ved at bruge en Header CheckBox
function ChangeCheckBoxState(id, checkState)
{
    var cb = document.getElementById(id);
    if (cb != null)
       cb.checked = checkState;
}

function ChangeAllCheckBoxStates(checkState)
{
    // Toggles through all of the checkboxes defined in the CheckBoxIDs array
    // and updates their value to the checkState input parameter
    if (CheckBoxIDs != null)
    {
        for (var i = 0; i < CheckBoxIDs.length; i++)
           ChangeCheckBoxState(CheckBoxIDs[i], checkState);
    }
}

function ChangeHeaderAsNeeded()
{
    // Whenever a checkbox in the GridView is toggled, we need to
    // check the Header checkbox if ALL of the GridView checkboxes are
    // checked, and uncheck it otherwise
    if (CheckBoxIDs != null)
    {
        // check to see if all other checkboxes are checked
        for (var i = 1; i < CheckBoxIDs.length; i++)
        {
            var cb = document.getElementById(CheckBoxIDs[i]);
            if (!cb.checked)
            {
                // Whoops, there is an unchecked checkbox, make sure
                // that the header checkbox is unchecked
                ChangeCheckBoxState(CheckBoxIDs[0], false);
                return;
            }
        }
        
        // If we reach here, ALL GridView checkboxes are checked
        ChangeCheckBoxState(CheckBoxIDs[0], true);
    }
}