// JScript File
var globalCheckBox;

function Resize()
{
     var myDiv = document.getElementById("centrepanel");
     myDiv.style.height = (document.body.parentNode.clientHeight - myDiv.offsetTop - 80)  + "px";
}


function SetContentHeight()
{
	// set the height to force comparison
	var el = document.getElementById('centrepanel');
			
	el.style.height = 0;
		
	// compare heights and resize as necessary
	if (el.offsetHeight + GetAbsoluteOffsetTop(el.id) < document.body.clientHeight)
	{
		el.style.height = document.body.clientHeight - 15 - GetAbsoluteOffsetTop(el.id) + 'px';
	}
}
		
function GetAbsoluteOffsetLeft(elementId)
{
	var el = document.getElementById(elementId);
	var offsetLeft = el.offsetLeft;
	while (el.offsetParent)
	{
		el = el.offsetParent;
		offsetLeft += el.offsetLeft;
	}
	
	return offsetLeft;
}

function GetAbsoluteOffsetTop(elementId)
{
	var el = document.getElementById(elementId);
	
	var offsetTop = el.offsetTop;
	while (el.offsetParent)
	{
		el = el.offsetParent;
		offsetTop += el.offsetTop;
	}
	
	return offsetTop;
}

function SetControlFocus(controlId)
{ 
    var control = document.getElementById(controlId);
    if(control != null)
    {
        control.focus();
    }
}

function MouseOver(controlId)
{

    var control = document.getElementById(controlId);
    if(control != null)
    {
        control.style.backgroundColor = "Red";
    }
}

function MouseOut(controlId)
{
    var control = document.getElementById(controlId);
    if(control != null)
    {
        control.style.backgroundColor = "White";
    }
}

function CheckAddress(oSrc, args)
{
    args.IsValid = (args.Value != "");
}

function CheckSize(oSrc, args)
{
    if(args.Value.length > 3999)
    {
        args.IsValid = false;
    }
    else
    {
        args.IsValid = true;
    }
}

function CheckSize2(oSrc, args)
{
    if(args.Value.length > 1999)
    {
        args.IsValid = false;
    }
    else
    {
        args.IsValid = true;
    }
}


function EnableDisableButton(textBoxId, buttonId)
{
     var textBox = document.getElementById(textBoxId);
     var button = document.getElementById(buttonId);
     if(textBox.value == "")
     {
        alert('indtast en gyldig email');
        textBox.focus();
        return false;
     }
     else
     {
        return true;
     }
}

function ResetFields(textBoxIds)
{
    var textBoxIdArray = textBoxIds.split('|');
    
    for(var x = 0; x < textBoxIdArray.length; x++)
    {
        document.getElementById(textBoxIdArray[x]).value = "";
    }
    return false;
}

function CheckAddress(source,args) 
{
    if (args.Value == 0) 
    {
        args.IsValid = false;
        return false;
    } 
}

function CheckContactMethod(source,args) 
{
    if (args.Value == 0) 
    {
        args.IsValid = false;
        return false;
    } 
}

function EmptyUploadFileWarning(fileUploaderID, errorMessage)
{
    var fileUploader = document.getElementById(fileUploaderID);
    var fileName = fileUploader.value;
    if(fileName == null || fileName == "")
    {
        alert(errorMessage);
        return false;
    }
    return true;
}

function MaxSizeWarning(maxsize)
{
    alert("Du kan uploade op til " + maxsize + "MB");
    return false;
}

function IllegalFileWarning(fileUploaderID, legalExtensions, errorMessage)
{
    var fileUploader = document.getElementById(fileUploaderID);
    var fileExtension = GetFileExtension(fileUploader.value.toLowerCase());
    if(fileExtension != null && fileExtension != "")
    {
        var legalExtensionsArray = legalExtensions.split(';');
        for(var x = 0; x < legalExtensionsArray.length; x++)
        {
            if(fileExtension == legalExtensionsArray[x])
            {
                   return true;
            }
        }
        alert(errorMessage);
        return false;
    }
}

function GetFileExtension(fileName)
{
    var index = fileName.lastIndexOf('.');
    if(index > -1)
    {
        return fileName.substring(index);
    }
    return "";
}

function TitleEntered(txtTitleId, errorMessage)
{
    var txtTitle = document.getElementById(txtTitleId);
    if(txtTitle.value == "")
    {
        alert(errorMessage);
        return false;
    }
    else
    {
        return true;
    }
}

function FileExist(filesAlreadyAdded, fileUploaderID, errorMessage)  
{
    if(filesAlreadyAdded != "")
    {
        var filesAlreadyAddedArray = filesAlreadyAdded.split(';');
        var fileUploader = document.getElementById(fileUploaderID);
        var newFile = GetFileName(fileUploader.value);
        if(newFile != "")
        {
            for(var x = 0; x < filesAlreadyAddedArray.length; x++)
            {
                if(filesAlreadyAddedArray[x] == newFile)
                {
                    return confirm(errorMessage);
                } 
            }
            return true;
        }
        else
        {
            return false;
        }
    }
    else
    {
        return true;
    } 
}

function GetFileName(fullFileName)
{
    var index = fullFileName.lastIndexOf('/');
    if(index == -1)
    {
        index = fullFileName.lastIndexOf('\\');
    }
    if(index > -1)
    {
        fullFileName = fullFileName.substring(index+1);
        return fullFileName;
    }
    if(fullFileName != "")
    {
        return fullFileName;
    }
    else
    {
        alert('Invalid file');
        return "";
    }
}

function SelecDeselect(checkbox)
{
   var isChecked = checkbox.checked? true: false;
   
   var theForm = document.forms[0];
    for(i=0; i<theForm.elements.length; i++)
    {
        if(theForm.elements[i].type == "checkbox")
        {
            theForm.elements[i].checked = isChecked;
        }
    }
}

function ShowConfirmDeleteMessage(checkBoxesId)
{
    var checkBoxControl;
    var checkBoxesArray = checkBoxesId.split(';');
    for(var x = 0; x < checkBoxesArray.length; x++)
    {
        checkBoxControl = document.getElementById(checkBoxesArray[x]);
        if(checkBoxControl.checked);
        {
            return confirm('Are you sure you want to delete selected items?');
        }
    }
    alert('No files were selected');
    return false;
}

function IsEmailSelected(checkBoxesId)
{
    var checkBoxControl;
    var checkBoxesArray = checkBoxesId.split(';');
    for(var x = 0; x < checkBoxesArray.length; x++)
    {
        checkBoxControl = document.getElementById(checkBoxesArray[x]);
        if(checkBoxControl.checked);
        {
            return true;
        }
    }
    alert('Ingen e-mails blev udvalgt');
    return false;
}


function SelectDeselct2(checkBoxId, textBoxId, fileName, allCheckBoxes)
{
      var otherOheckBox;
      var textBox = document.getElementById(textBoxId);
      var checkBox = document.getElementById(checkBoxId);
     
      var checkBoxArray = allCheckBoxes.split(';');
      for(var x = 0; x < checkBoxArray.length; x++)
      {
           if(checkBoxArray[x] != checkBoxId) 
           {
                otherOheckBox = document.getElementById(checkBoxArray[x]);
                otherOheckBox.checked = false;
           }
      } 
      if(checkBox.checked)
      {
            textBox.value = fileName;
      }
      else
      {
           textBox.value = ""; 
      }
}
var globalAllCheckBoxes;
function SetGlobalAllCheckBoxes(globalAllCheckBoxes)
{
   this.globalAllCheckBoxes = globalAllCheckBoxes;
}

function SelectDeselct3(checkBoxId)
{
      var selected = false;
      var checkBox;
      var checkBoxArray = globalAllCheckBoxes.split(';');
      for(var x = 0; x < checkBoxArray.length; x++)
      {
            checkBox = document.getElementById(checkBoxArray[x]);
            if(checkBox != null && checkBox.checked)
            {
                selected = true;
            }
      }
      if(!selected)
      {
        document.getElementById(checkBoxId).checked = false;
      }
      else
      {
            for(var x = 0; x < checkBoxArray.length; x++)
            {
                checkBox = document.getElementById(checkBoxArray[x]);
                if(checkBox != null && !checkBox.checked)
                {
                    selected = false;
                }
            }
            if(selected)
            {
                checkBox = document.getElementById(checkBoxId);
                if(checkBox != null)
                {
                   checkBox.checked = true;
                }
            }
      }
} 


function SelectDeselct4(checkBoxId, allCheckBoxes)
{
      var parentCheckBox = document.getElementById(checkBoxId);
      var checkBoxArray = allCheckBoxes.split(';');
      
      for(var x = 0; x < checkBoxArray.length; x++)
      {
            checkBox = document.getElementById(checkBoxArray[x]);
            if(checkBox != null)
            {
                if(parentCheckBox.checked)
                {
                    checkBox.checked = true;
                }
                else
                {
                    checkBox.checked = false;
                }
            }
      }
      SelecDeselectAll();
 }
 
 function SelectDeselct5(originator, checkBoxId, allCheckBoxes)
 {
      var selected = false;
      
      selected = originator.checked;
      var parentCheckBox = document.getElementById(checkBoxId);
      var ckbSelectAddresses = document.getElementById("ckbSelectAddresses");
      
      //If any checkbox is not selected then the original will not be
      if(!originator.checked)
      {
        parentCheckBox.checked = false;
        ckbSelectAddresses.checked = false;
        return;
      }
      
      var checkBoxArray = allCheckBoxes.split(';');
      
      for(var x = 0; x < checkBoxArray.length; x++)
      {
        if(checkBoxArray[x] != originator.id)
        {
            checkBox = document.getElementById(checkBoxArray[x]);
            if(checkBox.checked != selected)
            {
                SelecDeselectAll();
                return;
            }
        }
      }
      parentCheckBox.checked = originator.checked;
      SelecDeselectAll();
 }
 
 function SelecDeselectAll()
 {
        var ckbSelectAddresses = document.getElementById("ckbSelectAddresses");
        var theForm = document.forms[0];
        for(i=0; i<theForm.elements.length; i++)
        {
            if(theForm.elements[i].type == "checkbox" && 
            theForm.elements[i] != ckbSelectAddresses && 
            !theForm.elements[i].checked)
            {
                ckbSelectAddresses.checked = false;
                return;
            }
        }
        ckbSelectAddresses.checked = true;
    
}

function SelectHeaderCheckBox(checkBoxId, allCheckBoxes)
{
      var selected = true;
      var checkBox;
      var checkBoxArray = allCheckBoxes.split(';');
      for(var x = 0; x < checkBoxArray.length; x++)
      {
            checkBox = document.getElementById(checkBoxArray[x]);
            if(checkBox != null && !checkBox.checked)
            {
                selected = false;
            }
      }
      
      if(selected == true)
      {
         var headerCheckBox = document.getElementById(checkBoxId);
         if(headerCheckBox != null)
         {
            headerCheckBox.checked = true;
         }
      }
}

function ClearSelectedImages(textBoxId, allCheckBoxes)
{
        var otherOheckBox;
        var textBox = document.getElementById(textBoxId);
        var checkBoxArray = allCheckBoxes.split(';');
        if(textBox.value == "")
        {
            for(var x = 0; x < checkBoxArray.length; x++)
            {
                otherOheckBox = document.getElementById(checkBoxArray[x]);
                otherOheckBox.checked = false;
           }
        } 
}

function WarningMessage(message)
{
      var checkBoxArray = globalAllCheckBoxes.split(';');
      
      var theForm = document.forms[0];
      for(i=0; i<theForm.elements.length; i++)
      {
        if(theForm.elements[i].type == "checkbox" && theForm.elements[i].checked)
        {
            return true;
        }
      }
      
      alert(message);
      return false;
}

function DisplayImage(sourceImage, url, imgId, title, lblTitleId)
{
    UpdateImageStyle(sourceImage);
    
    var img = document.getElementById(imgId);
    img.src = url;
    var lblTitle = document.getElementById(lblTitleId);
    lblTitle.innerHTML = title;  
}

function UpdateImageStyle(sourceImage)
{
    var allImages = document.images;
    
    for(i=0; i < allImages.length; i++)
    {
        if(sourceImage.src == allImages[i].src)
        {
            sourceImage.style.border = "2px solid red";
            sourceImage.style.padding = "2px";
        }
        else
        {
            allImages[i].style.borderColor = "";
            allImages[i].style.padding = "";
        }
    }
}

function AddDefaultBorder(displayImageId, displayImageUrl)
{
    var displayImage = document.getElementById(displayImageId);
    var allImages = document.images;
    
    for(i=0; i < allImages.length; i++)
    {
        if(allImages[i].id != displayImageId && allImages[i].src == displayImageUrl)
        {
            allImages[i].style.border = "2px solid red";
            allImages[i].style.padding = "2px";
        }
         else
        {
            allImages[i].style.borderColor = "";
            allImages[i].style.padding = "";
        }
    }
}
