// ********************************************************************************************************
//
//  Common javascripts used sitewide
//
//  function confirmlink( URL ) {
//      Displays a confirmation dialog allowing the user to cancel before requesting the URL
//
//  function displayHelp(HelpID)
//      Shows the helplayer identified by HelpID ('AUTO','UBB','HTML')
//
//  Revision
//  20040210    JLS     validateStoryForm now checks for AuthorID and Online
//              JLS     validateStoryForm is now called validateObjectForm
//  20030415    JLS     Added confirmLink( url )
//  20001116    JSK     Created the script
//
// ********************************************************************************************************

function displayHelp(HelpID) {
  // Shows the helplayer identified by HelpID
  // Used by
  //  /templates/comments/CreateComment.tpl

  // Do not display any of the div's
  var HelpDiv = document.getElementById('HelpAUTO');
  HelpDiv.style.display='none';
  var HelpDiv = document.getElementById('HelpUBB');
  HelpDiv.style.display='none';
  var HelpDiv = document.getElementById('HelpHTML');
  HelpDiv.style.display='none';

  // Display the selected div
  var HelpDiv = document.getElementById('Help' + HelpID);
  HelpDiv.style.display='';
}

// Confirm action function
function confirmLink(URL)
{

    // Displays a confirmation dialog allowing the user to cancel before requesting the URL
    if (confirm("Er du sikker?")) {

        window.location.href = URL;

    }

}

// Validate for in EditStory.tpl
function validateObjectForm(theForm)
{

    // Validate category
    var categoryElement = document.getElementById("Categories[]");
    if (categoryElement && parseInt(categoryElement.selectedIndex)<1) {

        alert("Du skal angive mindst én kategori");
        return false;

    }

    // Validate filter
    if (parseInt(theForm.elements["Filters[]"].selectedIndex)<1) {

        alert("Du skal angive mindst én kanal");
        return false;

    }

    // Validate headline
    if (theForm.elements["Title"].value.length==0) {

        theForm.elements["Title"].focus();
        alert("Du skal skrive en titel");
        return false;

    }

    // Validate teaser
    var element = document.getElementById("Teaser");
    if (element && element.value.length==0) {

        element.focus();
        alert("Du skal skrive en teaser tekst");
        return false;

    }

    // Validate author
    var element = document.getElementById("AuthorID");
    if (element && element.value.length==0) {
        element.focus();
        alert("Du skal angive en forfatter");
        return false;

    }

    // Validate online
    if (theForm.elements["Online"].value.length==0) {

        theForm.elements["Online"].focus();
        alert("Du skal angive en online-tid");
        return false;

    }

    return true;
}

