﻿// Henter navnene på alle textareas
function GetTextAreaname()
{
    for (var loop = 0; loop < document.forms['aspnetForm'].elements.length; loop++)
    {
        if(document.forms['aspnetForm'].elements[loop].type == 'textarea')
        {
            return document.forms['aspnetForm'].elements[loop].id;	
        }
    }
}

// Tilføjer tekst til et textarea
function AddText(startTag,defaultText,endTag)
{
    //var textBox=MyMasterPage_ContentPlaceHolderMain_DetailsViewAdmin_DetailsView1_TextBoxTekst;
    with(document.getElementById("aspnetForm")) //
    {
        if (MyMasterPage_ContentPlaceHolderMain_DetailsViewAdmin_DetailsView1_TextBoxTekst.createTextRange != null)
        {
            var text;        
            MyMasterPage_ContentPlaceHolderMain_DetailsViewAdmin_DetailsView1_TextBoxTekst.focus(MyMasterPage_ContentPlaceHolderMain_DetailsViewAdmin_DetailsView1_TextBoxTekst.caretPos); 
            MyMasterPage_ContentPlaceHolderMain_DetailsViewAdmin_DetailsView1_TextBoxTekst.caretPos = document.selection.createRange().duplicate();
            if(MyMasterPage_ContentPlaceHolderMain_DetailsViewAdmin_DetailsView1_TextBoxTekst.caretPos.text.length>0)
            {
                var sel = MyMasterPage_ContentPlaceHolderMain_DetailsViewAdmin_DetailsView1_TextBoxTekst.caretPos.text;
                var fin = '';
                while(sel.substring(sel.length-1, sel.length)==' ')
                {
                    sel = sel.substring(0, sel.length-1)
                    fin += ' ';
                }
                MyMasterPage_ContentPlaceHolderMain_DetailsViewAdmin_DetailsView1_TextBoxTekst.caretPos.text = startTag + sel + endTag + fin;
            }
            else
            MyMasterPage_ContentPlaceHolderMain_DetailsViewAdmin_DetailsView1_TextBoxTekst.caretPos.text = startTag+defaultText+endTag;
        }
        else 
	    {
		    var selLength = MyMasterPage_ContentPlaceHolderMain_DetailsViewAdmin_DetailsView1_TextBoxTekst.textLength;
		    var selStart = MyMasterPage_ContentPlaceHolderMain_DetailsViewAdmin_DetailsView1_TextBoxTekst.selectionStart;
		    var selEnd = MyMasterPage_ContentPlaceHolderMain_DetailsViewAdmin_DetailsView1_TextBoxTekst.selectionEnd;
		    var oldScrollTop = MyMasterPage_ContentPlaceHolderMain_DetailsViewAdmin_DetailsView1_TextBoxTekst.scrollTop;
		    var s1 = (MyMasterPage_ContentPlaceHolderMain_DetailsViewAdmin_DetailsView1_TextBoxTekst.value).substring(0,selStart);
		    var s2 = (MyMasterPage_ContentPlaceHolderMain_DetailsViewAdmin_DetailsView1_TextBoxTekst.value).substring(selStart, selEnd)
		    var s3 = (MyMasterPage_ContentPlaceHolderMain_DetailsViewAdmin_DetailsView1_TextBoxTekst.value).substring(selEnd, selLength);
		    MyMasterPage_ContentPlaceHolderMain_DetailsViewAdmin_DetailsView1_TextBoxTekst.value = s1 + startTag + s2 + endTag + s3;
		    MyMasterPage_ContentPlaceHolderMain_DetailsViewAdmin_DetailsView1_TextBoxTekst.selectionStart = s1.length;
		    MyMasterPage_ContentPlaceHolderMain_DetailsViewAdmin_DetailsView1_TextBoxTekst.selectionEnd = s1.length + s2.length + wrap1.length + wrap2.length;
		    MyMasterPage_ContentPlaceHolderMain_DetailsViewAdmin_DetailsView1_TextBoxTekst.scrollTop = oldScrollTop;
		    MyMasterPage_ContentPlaceHolderMain_DetailsViewAdmin_DetailsView1_TextBoxTekst.focus();
	    }
    }
}

// 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++;
}

// Funktion der beregner browser vinduesstørrelsen
function BrowserSizeCalculater()
{
  var BrowserSizeArray = new Array();
  var browserWidth = 0, browserHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    browserWidth = window.innerWidth;
    browserHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    browserWidth = document.documentElement.clientWidth;
    browserHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    browserWidth = document.body.clientWidth;
    browserHeight = document.body.clientHeight;
  }
  
  BrowserSizeArray[0] = browserWidth;
  BrowserSizeArray[1] = browserHeight;
  
  return BrowserSizeArray;
}

// Funktion der beregner størrelsen af HTML og BODY elementerne
function ElementSize(element)
{
  var BrowserSizeArray = new Array();
  BrowserSizeArray = BrowserSizeCalculater();
  
  element.width = 1;
  element.height = BrowserSizeArray[1]-150;
}

// Funktion der ændrer billedestørrelsen så den passer til browser-størrelsen
function imagesize(img)
{
  var BrowserSizeArray = new Array();
  BrowserSizeArray = BrowserSizeCalculater();

  var imgWidth = 0, imgHeight = 0, imgWidthDiff = 0, imgHeightDiff = 0;
  imgWidth = img.width;
  imgHeight = img.height
  imgWidthDiff = imgWidth-BrowserSizeArray[0];
  imgHeightDiff = imgHeight-BrowserSizeArray[1];
  
  if(imgWidthDiff > 0 && imgWidthDiff >= imgHeightDiff){
    img.width = BrowserSizeArray[0]-120;
  }
  else if(imgHeightDiff > 0 && imgWidthDiff < imgHeightDiff){
    img.height = BrowserSizeArray[1]-120;
  }
  
}

// Funktion der ændrer billedestørrelsen så den passer til browser-størrelsen
function imageurl(img)
{
  document.getElementById(img).src = "Uploads/Collage/Thumbnails/Dock.jpg";  
}

// 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);
    }
}


function ChangeAllCheckBoxStatesDirectories(checkState)
{
    // Toggles through all of the checkboxes defined in the CheckBoxIDs array
    // and updates their value to the checkState input parameter
    if (CheckBoxIDsDirectories != null)
    {
        for (var i = 0; i < CheckBoxIDsDirectories.length; i++)
           ChangeCheckBoxState(CheckBoxIDsDirectories[i], checkState);
    }
}

function ChangeHeaderAsNeededDirectories()
{
    // 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 < CheckBoxIDsDirectories.length; i++)
        {
            var cb = document.getElementById(CheckBoxIDsDirectories[i]);
            if (!cb.checked)
            {
                // Whoops, there is an unchecked checkbox, make sure
                // that the header checkbox is unchecked
                ChangeCheckBoxState(CheckBoxIDsDirectories[0], false);
                return;
            }
        }
        
        // If we reach here, ALL GridView checkboxes are checked
        ChangeCheckBoxState(CheckBoxIDsDirectories[0], true);
    }
}

function ChangeImage(img_name, img_src) {
    document.getElementById(img_name).src = img_src;
}
