/* 
 * Unobtrusive javascript for onload event
 * Version 1.0
 * released 6.6.2006
*/

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

// This method replaces the default form action with an ssl action
function SwitchToSsl(sslUrl)
{
    var startsWithUrl = __CMS_CurrentUrl.substring(5,0);
    if(__CMS_CurrentUrl != null && startsWithUrl != "https")
    {
        __CMS_CurrentUrl = sslUrl + __CMS_CurrentUrl;
    }
}

// This method toggles the help message for the registration process to visible
function ShowHelpMessage()
{
  var helpBlock = document.getElementById("helpblock");
  helpBlock.style.display = '';
}

// This method toggles the help message for the registration process to invisible
function HideHelpMessage()
{
  var helpBlock = document.getElementById("helpblock");
  helpBlock.style.display = "none";
}

// This method opens a popup centered on the screen
function openPopup(url, width, height)
{
  var posLeft = (screen.availWidth - width) / 2;
  var posTop = (screen.availHeight - height) / 2;
  
  var features = "location=no, menubar=yes, resizable=yes, scrollbars=yes, status=yes, titlebar=no, toolbar=no";
  
  features += ", width=" + width;
  features += ", height=" + height;
  features += ", left=" + posLeft;
  features += ", top=" + posTop;
       
  window.open(url, "_blank", features);
}

// This message renders a yes/no dialog with the supplied message
function ShowConfirm(message)
{
    return confirm(message);
}

// This method shows a yes no dialog during the registration process when the user does not choose to receive mailings
function CheckMailings(mailingsCheckboxID)
{
    if( mailingsCheckboxID != null )
    {
        var mailingsCheckbox = document.getElementById(mailingsCheckboxID);
        
        if( mailingsCheckbox != null && mailingsCheckbox.checked == false )
        {
            return ShowConfirm("Weet u zeker dat u geen mailings wilt ontvangen? Hierdoor wordt u niet op de hoogte gehouden over aanbiedingen.");    
        }
    }
}

// This method renders a confirmation after a user saves changes. It will check for a valid page first.
function ShowSavedConfirmation()
{
    Page_ClientValidate('');
    
    /*if( Page_IsValid )
    {    
        alert('De gegevens zijn opgeslagen.');
    }*/
}

// This method renders a status confirmation after the user has registered a customer. If all went fine then the user is redirected to the supplied page.
function ShowRegistrationConfirmation(hasRights, redirectUrl)
{
    if(hasRights)
    {
        alert('De klant is succesvol aangemeld. U wordt nu automatisch naar de klantenbeheer-pagina doorgestuurd.');
        window.location = redirectUrl;
    }
    else
    {
        alert('De klant is aangemeld maar heeft geen recht op het programma. Controleer de ingevoerde gegevens.');
    }
}

  ///Method that indicates if a asp.net validator control is triggered
function ValidatorIsTriggered(validatorId)
{
   return document.getElementById(validatorId).style.display == 'inline';
}
