﻿// JScript File


//Usage: openWindow( url , w , h , tb , stb , L , mb , sb , rs , x , y ) 

//url - The URL of the page to open. Example: "http://scriptasylum.com". 
//w - The width of the window in pixels. 
//h - The height of the window in pixels (doesn't include menubars). 
//tb - Toolbar visible? 1 = yes, 0 = no. 
//stb - Status bar visible? 1 = yes, 0 = no. 
//L - Linkbar visible? 1 = yes, 0 = no. 
//mb - Menubar visible? 1 = yes, 0 = no. 
//sb - Scrollbars visible? 1 = yes, 0 = no. 
//rs - Resizable window? 1 = yes, 0 = no. 
//x - The horizontal position of the window from the left of the screen. 
//y - The vertical position of the window from the top of the screen.
//ct - centers the new window to the screen if = 1
function openWindow(url, w, h, tb, stb, l, mb, sb, rs, x , y, ct)
{
    if (ct === 1)
    {
        x = (screen.Width / 2) - (w/2);
        y = (screen.Height / 2) - (h/2);
    }
    if (tb == null)     tb = 0;
    if (stb == null)     stb = 0;
    if (l == null)     l = 0;
    if (mb == null)     mb = 0;
    if (sb == null)     sb = 0;
    if (x == null)     x = 10;
    if (y == null)     y = 10;
    if (ct == null)     ct = 0;
    
    var t = (document.layers)? ',screenX='+x+',screenY='+y: ',left='+x+',top='+y;
    
    //A LITTLE CROSS-BROWSER CODE FOR WINDOW POSITIONING
    tb=(tb)?'yes':'no'; stb=(stb)?'yes':'no'; l=(l)?'yes':'no';
    mb=(mb)?'yes':'no'; sb=(sb)?'yes':'no'; rs=(rs)?'yes':'no';
        

    
    var x=window.open(url, 'newWin'+new Date().getTime(), 'scrollbars='+sb+',width='+w+',height='+h+',toolbar='+tb+',status='+stb+',menubar='+mb+',links='+l+',resizable='+rs+t);
    
    x.focus();
}


function hideControl(id)
{
  //safe function to hide an element with a specified id
  if (document.getElementById)
  {
    // DOM3 = IE5, NS6
    if (document.getElementById(id))
        document.getElementById(id).style.display = 'none';
  }
  else
  {
    if (document.layers)
    {
      // Netscape 4
      if (document.id)
        document.id.display = 'none';
    }
    else
    {
      // IE 4
      if (document.all.id)
        document.all.id.style.display = 'none';
    }
  }
}

function hideOpenerControl(id)
{
  //safe function to hide an element with a specified id
  if (opener.document.getElementById)
  {
    // DOM3 = IE5, NS6
    if (opener.document.getElementById(id))
        opener.document.getElementById(id).style.display = 'none';
  }
  else
  {
    if (opener.document.layers)
    {
      // Netscape 4
      if (opener.document.id)
        opener.document.id.display = 'none';
    }
    else
    {
      // IE 4
      if (opener.document.all.id)
        opener.document.all.id.style.display = 'none';
    }
  }
}

function showControl(id)
{
  //safe function to show an element with a specified id
    
  if (document.getElementById)
  {
    // DOM3 = IE5, NS6
    if (document.getElementById(id))
        document.getElementById(id).style.display = 'block';
  }
  else
  {
    if (document.layers)
    {
      // Netscape 4
      if (document.id)
        document.id.display = 'block';
    }
    else
    {
      // IE 4
      if (document.all.id)
        document.all.id.style.display = 'block';
    }
  }
}
function showOpenerControl(id)
{
  //safe function to show an element with a specified id
    
  if (opener.document.getElementById)
  {
    // DOM3 = IE5, NS6
    if (opener.document.getElementById(id))
        opener.document.getElementById(id).style.display = 'block';
  }
  else
  {
    if (opener.document.layers)
    {
      // Netscape 4
      if (opener.document.id)
        opener.document.id.display = 'block';
    }
    else
    {
      // IE 4
      if (opener.document.all.id)
        opener.document.all.id.style.display = 'block';
    }
  }
}

// Start of Javascript DropdownList Typing selector code i.e it will select the item corresponding to your multiple keypresse
// use ESC key to reset.
// To use with HTML dropdown control add this code: onkeypress="evalKey()"
// Don't forget to include this .js file in the HTML
var tString = '';
var lsf = 0;// last successful index

timerDDL = null;

function StartDDLTimer()
{
  // Reset the timer
  StopDDLTimer();
  timerDDL = setTimeout("javascript:__doPostBack();", 500);
}

function StopDDLTimer()
{
  if (timerDDL != undefined)
  {
    clearTimeout(timerDDL);
  }
}
         
function evalKey()
{
    // Global Variables
    var i = 0; 
    var success = false;
    var elem = event.srcElement;
    var tLowElemText = '';
    // Get the unicode char of the keypress
    var eCode = event.keyCode;
    // Check if it's a vaid ASCII Character
    if (eCode == 27)
    {
        tString = ''; 
        elem.selectedIndex = 0;
    }
    else
    {
      var letterDigitPattern = new RegExp("^\\w+$");
      if (letterDigitPattern.test(String.fromCharCode(eCode)) == true)
      {
        // Convert the Code to the corresponding character and add to searchstring
        tString += String.fromCharCode(eCode);
        // ... and perform the search starting from the top element in the listbox
        while (success == false) 
        {
          i = 0;
          // Convert everything to lowercase; allows an easy comparison
          var tLowString = tString.toLowerCase();
          // Compose the regexp searchstring ...
          var rExpr = eval("/^" +  tLowString + "/");
          while ((i < elem.length)&& (success == false) )
          {
            tLowElemText = elem.options[i].text.toLowerCase();
            // success: Position the listbox on the (first) found element
            if (tLowElemText.search(rExpr) != -1)
            {
              elem.selectedIndex = i;
              success = true;
              if (event.srcElement.onchange != null)
              {
                event.srcElement.onchange();
              }
            }
            else
            {
              i++;
            }
          } // while i < elem.length
          // if nothing is found in the entire list, the last character of the
          //searchstring is removed to allow typing the correct 'next' character
          if (success == false)
          {
            tString = tString.substr(0, tString.length-1);
          }
        } // while success = false
        
        window.event.returnValue = false;
        window.event.cancelBubble = true; 
      }
    }
}

function evalKeyWithPostBack()
{
    // Global Variables
    var i = 0; 
    var success = false;
    var elem = event.srcElement;
    var tLowElemText = '';
    // Get the unicode char of the keypress
    var eCode = event.keyCode;
    // Check if it's a vaid ASCII Character
    if (eCode == 27)
    {
        tString = ''; 
        elem.selectedIndex = 0;
        StopDDLTimer();
    }
    else
    {
      var letterDigitPattern = new RegExp("^\\w+$");
      if (letterDigitPattern.test(String.fromCharCode(eCode)) == true)
      {
        StartDDLTimer();
       
        // Convert the Code to the corresponding character and add to searchstring
        tString += String.fromCharCode(eCode);
        // ... and perform the search starting from the top element in the listbox
        while (success == false) 
        {
          i = 0;
          // Convert everything to lowercase; allows an easy comparison
          var tLowString = tString.toLowerCase();
          // Compose the regexp searchstring ...
          var rExpr = eval("/^" +  tLowString + "/");
          while ((i < elem.length)&& (success == false) )
          {
            tLowElemText = elem.options[i].text.toLowerCase();
            // success: Position the listbox on the (first) found element
            if (tLowElemText.search(rExpr) != -1)
            {
              elem.selectedIndex = i;
              success = true;
              if (event.srcElement.onchange != null)
              {
                event.srcElement.onchange();
              }
            }
            else
            {
              i++;
            }
          } // while i < elem.length
          // if nothing is found in the entire list, the last character of the
          //searchstring is removed to allow typing the correct 'next' character
          if (success == false)
          {
            tString = tString.substr(0, tString.length-1);
          }
        } // while success = false
        
        window.event.returnValue = false;
        window.event.cancelBubble = true; 
      }
    }
}
// End of Javascript DropdownList Typing selector code

function ConfirmDelete (addExpl) {
   var txtExpl = "Er du sikker";
   //if (addExpl != null) txtExpl += " to delete this " + addExpl;
   txtExpl += "?";
   return (confirm (txtExpl));
}  

function checkAgreement (arg1, arg2, checkBoxId) {

    var result = false;
    var chkID = "ctl00$MainContentPlaceHolder$chkLicenceAgreement";
    var objCheck = document.forms[0][chkID];
    if (objCheck.checked)
        result = true;
    arg2.IsValid = result;
}   

function doPaymentPopup(toURL, rbID) {
  var objRD = document.forms[0][rbID];

  if (objRD && objRD.checked) {
      var newwin = null;
      newwin = window.open(toURL, 'paywin', 'scrollbars,status,width=550,height=600');
      newwin.focus();
      return false;
  } else {
    return true;
  }
}
    
function setCustomFocus(controlID)
{
    document.getElementById(controlID).focus();
}
