// *************************************************************************************************
// *** Unsorted.
// *************************************************************************************************

function goHome(){
   if(navigator.userAgent.indexOf('iPad') >= 0) top.location = COM_SERVER + '?ipad=true'; 
   else                                         top.location = COM_SERVER + '/';
}

function openValgomat(){
   com_openWindow('https:/' + '/lotto.kjapt.no/valgomat', 'valgomat',
  'width=1024,height=768,scrollbars=1,resizable=1,status=no');
}

function openWebTV(){
    frm_openDialogue(1123, 624, 'http://webtv.tv2.no/multimedia/webtv/dido/player-example-4.0.html?progId=467797 ');
}
function openWinner(){
   com_openWindow('https:/' + '/storvinnerdata.no', 'millionærkart',
  'width=880,height=980,scrollbars=1,resizable=1,status=no');

}
function openSpillevett(){
  com_openWindow('http:/' + '/www.spillevett.no', 'Spillevett',
  'width=870,height=640,toolbar=0,location=center,directories=0,status=0,menubar=0,resizable=1,scrollbars=1');
}

function openSpillevettAgeLimit(){
  com_openWindow('http:/' + '/www.spillevett.no/forside/v%C3%A5rt+arbeid/aldersgrenser', 'Spillevett',
  'width=870,height=640,toolbar=0,location=center,directories=0,status=0,menubar=0,resizable=1,scrollbars=1');
}

function openHjelpelinjen(){
  com_openWindow('http:/' + '/www.hjelpelinjen.no', 'Hjelpelinjen',
  'width=1070,height=850,toolbar=0,location=center,directories=0,status=0,menubar=0,resizable=1,scrollbars=1');
}

function openTabellservice(){
  //com_openWindow('http:/' + '/norsktipping.speaker.no', 'Tabellservice',
  //com_openWindow('http:/' + '/norsktipping.speaker.no/Default.aspx?0=2&1=Fotball&2=Norge&3=2010 - 2010&4=307598&5=&6', 'Tabellservice', 
  com_openWindow('http:/' + '/stats.betradar.com/s4/?clientid=160&language=no', 'Tabellservice',
  'width=985,height=606,toolbar=0,location=center,directories=0,status=0,menubar=0,resizable=1,scrollbars=1');
}
function openTalletEr()
{
  com_openWindow('/miscellaneous/getNumberStatisticsLotto.htm', 'talleter',
  'width=640,height=480,toolbar=0,location=center,directories=0,status=0,menubar=0,resizable=1,scrollbars=0');
}
function openGuide(fileName) {
  guideWidth = 240;
  guideWidth = guideWidth + 30;
  var wLeft = window.screen.availWidth - guideWidth;
  var wHeight = window.screen.availHeight;
  
  window.top.moveTo(0, 0); window.top.resizeTo(wLeft, wHeight);
  var windowref = window.open('javascript:close();','guideWindow');
  var guideWindow = window.open('', 'guideWindow',
  'scrollbars=0, resizable=0, menubar=0, location=0, personalbar=0,' +
  'titlebar=0, toolbar=0, status=0, left=' + wLeft + ', top=0, ' +
  'width=' + guideWidth + ', height=' + wHeight);
  try
  {
  var guideLeftPos = window.screen.availWidth - guideWidth;
  var screenAvailHeight = window.screen.availHeight;
  guideWindow.top.resizeTo(guideWidth, screenAvailHeight);
  guideWindow.top.moveTo(guideLeftPos, 0);
  }
  catch (Exception)
  {}
  window.top.resizeTo(window.screen.availWidth - guideWidth, screenAvailHeight);
  window.top.moveTo(0, 0);
  guideWindow.location.href = fileName;
  guideWindow.focus();
}

function dcsMultiTrack(){
   for (var i=0;i<arguments.length;i++){
     if (arguments[i].indexOf('WT.')==0){
     WT[arguments[i].substring(3)]=arguments[i+1];
     i++;
     }
     if (arguments[i].indexOf('DCS.')==0){
       DCS[arguments[i].substring(4)]=arguments[i+1];
       i++;
     }
     if (arguments[i].indexOf('DCSext.')==0){
       DCSext[arguments[i].substring(7)]=arguments[i+1];
       i++;
     }
   }
   var dCurrent=new Date();
   DCS.dcsdat=dCurrent.getTime();
   dcsTag();
}

// *************************************************************************************************
// *** Functions.
// *************************************************************************************************

function frm_getBuypassURL()
{
  return ['https:/' + '/www.test2.buypass.no', 'https:/' + '/www.test3.buypass.no',
    'https:/' + '/www.test5.buypass.no', 'https:/' + '/www.buypass.no'][COM_DEPLOYMENT_STATE];
}
function frm_getSecureBuypassURL()
{                                           
  return ['https:/' + '/www.test2.buypass.no', 'https:/' + '/www.test3.buypass.no',
    'https:/' + '/www.test5.buypass.no', 'https:/' + '/secure.buypass.no'][COM_DEPLOYMENT_STATE];
}

// *************************************************************************************************
// If the user is logged in, return a parameter that will pass the user's Buypass ID to the server.
// Otherwise, return an empty string.
function frm_getBuypassID()
{
  if(frm_user == null) return '';
  return '&reqbuypassid=' + frm_user[FRM_BUYPASS_ID];
}

// *************************************************************************************************

function register()
{
// Ordinary
  //frm_openDialogue(1010, 720, frm_getBuypassURL() +
  frm_openDialogue(580, 670, frm_getBuypassURL() +
    '/bporder/pages/jsp/index.jsp?productId=105&cancelUrl=' + COM_SERVER +
    '/user-information/id/closeDialog.jsp&agent=996001');
}

function registerOTP(){
// With OTP
  // if iPad 
  if (navigator.userAgent.indexOf('iPad') >= 0) {
   top.location = COM_SERVER + '/user-information/logon.htm?loginMethod=5';
  }
  else {  
    frm_openDialogue(580, 650,  '/user-information/logon.htm?loginMethod=5');
  }
}


function changeCustomerInfoOTP()
{
  var status;

  if(frm_user != null) {
    //logged in
    status = frm_user[FRM_LOG_IN_STATUS];

    if (status != null){
      if (status != 'ips:NTSK'){
        frm_openDialogue(529, 665, frm_getBuypassURL() + '/bpotp/pages/jsp/index.jsp?productId=4521' + 
        '&otp=5' +
        '&toFunction=mainmenu' +
        '&cancelUrl='   + COM_SERVER + '/user-information/id/closeDialog.jsp' + frm_getBuypassID() +
        '&completeUrl=' + COM_SERVER + '/user-information/id/closeDialog.jsp' + frm_getBuypassID()); 
        return;  
       }
    }
  }
  // not logged in:
  frm_openDialogue(710, 820, frm_getBuypassURL() +
    '/bpedit/pages/jsp/index.jsp?productId=105&cancelUrl=' + COM_SERVER +
    '/user-information/id/closeDialog.jsp' + frm_getBuypassID()); 
}




function changeCustomerInfo()
{
  var status;

  if(frm_user != null) {
    //logged in

    status = frm_user[FRM_LOG_IN_STATUS];

    if (status != null){
      if (status != 'ips:NTSK'){
        alert('For å endre kundeinformasjon må du enten bruke spillerkort og kortleser eller gjøre det hos en kommisjonær');
        return;  
       }
    }
  }
  frm_openDialogue(710, 820, frm_getBuypassURL() +
    '/bpedit/pages/jsp/index.jsp?productId=105&cancelUrl=' + COM_SERVER +
    '/user-information/id/closeDialog.jsp' + frm_getBuypassID()); 
}


// *************************************************************************************************

function orderAdditionalCard()
{
  frm_openDialogue(710, 800, frm_getBuypassURL() +
    '/bpedit/pages/jsp/index.jsp?productId=105&toFunction=additionalCard&cancelUrl=' +
    COM_SERVER + '/user-information/id/closeDialog.jsp' + frm_getBuypassID());
}

// *************************************************************************************************

function approval()
{
  frm_openDialogue(710, 820, frm_getBuypassURL() +
    '/bpedit/pages/jsp/index.jsp?productId=105&toFunction=info&cancelUrl=' + COM_SERVER +
    '/user-information/id/closeDialog.jsp' + frm_getBuypassID());
}

// *************************************************************************************************

function orderCardReader()
{
  frm_openDialogue(1010, 830, frm_getBuypassURL() +
    '/bpwebstore/pages/jsp/campaine.jsp?productId=105' + frm_getBuypassID());
}

// *************************************************************************************************
// Renew the card with the given index. index is the index of the card in the frm_user object's
// FRM_CARDS list.
function frm_renewCard(index)
{
  frm_openDialogue(710, 760, frm_getBuypassURL() +
    '/bpedit/pages/jsp/index.jsp?productId=105&toFunction=renewCard&cardNumber=' +
    String(frm_user[FRM_CARDS][index][FRM_CARD_NO]) + frm_getBuypassID());
  }

// *************************************************************************************************
function pinSettings()
{
    // *** // The URL used to be "secure.testX.buypass.no". Will the current code work correctly?       
  frm_openDialogue(550, 466, frm_getSecureBuypassURL() +
    '/wips/service?op=WTMNT&toFunction=PINFUNC&eol=1&exm=3&pal=' + COM_SERVER +
    '/user-information/id/closeDialog.jsp' + frm_getBuypassID());
}
// *************************************************************************************************

function lostPIN()
{
    // *** // The URL used to be "secure.testX.buypass.no". Will the current code work correctly?
  frm_openDialogue(550, 466, frm_getSecureBuypassURL() +
    '/wips/service?op=WTMNT&toFunction=ORDERPUK&eol=1&exm=3&pal=' + COM_SERVER +
    '/user-information/id/closeDialog.jsp' + frm_getBuypassID());
}
// *************************************************************************************************

function orderMobileGames()
{
  frm_openDialogue(600, 800, frm_getBuypassURL() + '/bpmobile/pages/jsp/index.jsp?productId=172' +
    frm_getBuypassID());
}

// *************************************************************************************************
function cashManagement()
{
  //frm_openDialogue(550, 466, frm_getSecureBuypassURL() +
  //  '/wips/service?op=WTMNT&eol=1&exm=3&pal=' + COM_SERVER + '/user-information/id/closeDialog.jsp' +
  //  frm_getBuypassID());
 
  frm_openDialogue(550, 466, '/user-information/atm.htm');
}
// *************************************************************************************************

function withdrawal(){
  var status;

  if(frm_user != null) {
    //logged in
    status = frm_user[FRM_LOG_IN_STATUS];

    if (status != null){
      if (status != 'ips:NTSK'){
        alert('Denne direktelinken fungerer ikke når du er innlogget med brukernavn og passord, \nmen de er tilgjengelig via nettminibanken i hovedmenyen');
        return;  
       }
    }
  }
  //frm_openDialogue(550, 466, frm_getSecureBuypassURL() +
    //'/wips/service?op=WTMNT&toFunction=TRANSFER&eol=1&exm=3&pal=' + COM_SERVER +
    //'/user-information/id/closeDialog.jsp' + frm_getBuypassID());    
    frm_openDialogue(550, 466, '/user-information/atm.htm');
}
// *************************************************************************************************

function transactionLog(){
  var status;

  if(frm_user != null) {
    //logged in
    status = frm_user[FRM_LOG_IN_STATUS];

    if (status != null){
      if (status != 'ips:NTSK'){
        alert('Denne direktelinken fungerer ikke når du er innlogget med brukernavn og passord, \nmen de er tilgjengelig via nettminibanken i hovedmenyen');
        return;  
       }
    }
  }
  frm_openDialogue(550, 466, frm_getSecureBuypassURL() +
    '/wips/service?op=WTMNT&toFunction=TXLIST&eol=1&exm=3&pal=' + COM_SERVER +
    '/user-information/id/closeDialog.jsp' + frm_getBuypassID());
}
// *************************************************************************************************

function quickDownLoadMobil()
{
  frm_openDialogue(600, 800, frm_getBuypassURL() +
    '/bpotp/pages/jsp/index.jsp?productId=4521&completeUrl=' + COM_SERVER +
    '/produktinfo/nettspill/bli_nettspiller_velg/bli_nettspiller_mobil_id/bli_mobilspiller_velg/velkommen?mode=print&otp=3&cancelUrl=' +
    COM_SERVER + '/user-information/id/closeDialog.jsp');
}

// *************************************************************************************************

function downLoadMobil()
{
  frm_openDialogue(600, 800, frm_getBuypassURL() +
    '/bpotp/pages/jsp/index.jsp?productId=4521&completeUrl=' + COM_SERVER +
    '/produktinfo/nettspill/bli_nettspiller_velg/bli_nettspiller_mobil_id/bli_mobilspiller_velg/velkommen?mode=print&otp=4&cancelUrl=' +
    COM_SERVER + '/user-information/id/closeDialog.jsp');
}

// *************************************************************************************************

function showMultixBling()
{
  frm_openDialogue(730, 455, 'http:/' + '/www.ledgaming.com/BlingBling/BlingBling_online.dcr');
}

// *************************************************************************************************
// Show small media player. With or without id.
function showMediaPlayer(id)
{
  var url;
  
  url = 'https:/' + '/vms.qbrick.com/';
  if(id != null)
  {
    url += 'viral.aspx?imageurl=1&targetwindow=_blank&allowscriptaccess=1&width=480&height=292&';
    if(id != '') url += 'mid=' + String(id) + '&';
    frm_openDialogue(480, 292, url);
  }
  else
  {
    url += '?cid=3C020E24&mtf=0&msch=0&mrss=0&mrat=0&mld=0&mec=0&width=480&height=276&';  
    frm_openDialogue(480, 276, url);
  }
}

// *************************************************************************************************
// New 02.11.11
function showNewMediaPlayer(id)
{
  var url;  
  if(id != null)
  {
    url = 'https:/' + '/professional.player.qbrick.com/player.aspx?mcid=' + String(id) + '&width=480&height=265&as=0&fs=1&rp=0&cb=1&il=1&sp=1';    
    frm_openDialogue(480, 292, url);
  } 
}

function showNewMediaPlayerBig(id)
{
  var url;  
  if(id != null)
  {
    url = 'https:/' + '/professional.player.qbrick.com/player.aspx?mcid=' + String(id) + '&width=958&height=532&as=0&fs=1&rp=0&cb=1&il=1&sp=1';    
    frm_openDialogue(958, 532, url);
  } 
}

// *************************************************************************************************
// Show media player full size. With or without id.
function showMediaPlayerFull(id)
{
  var url;

  url = 'https:/' + '/vms.qbrick.com/ext/not';
  if(id != null){
        url += '/index.htm?id=' + String(id) + '&width=965&height=630&';
        alert(url);
  } 
  else  url += '?imageurl=1&targetwindow=_blank&allowscriptaccess=1&width=965&height=630&';
  frm_openDialogue(965, 630, url);
}

// *************************************************************************************************
// Show media player full size.
function showNewMediaPlayerFull()
{
  var url;
  url = 'https:/' + '/professional.player.qbrick.com/player.aspx?ccid=3C020E24C341EA03&amp;width=958&amp;height=532';
  frm_openDialogue(958, 532, url);
}

// *************************************************************************************************
//  Create Keno coupon given 10 random numbers
//  Rekkepris = 5,-    Antall dager = 14  Kenonivå = 10
//  TO DO:Use parameters to ajust the input values
function numberorder(a,b){return a-b;}
function keno(tag){    
    var maxNumbers = 70;
    var maxRandomNumbers = 10;
	var AvailNum		= new Array();				// holds the available numbers 
	var ChosenNum		= new Array();	            // holds the chosen numbers 
	var numOfAvailNumbers	= 70;
	var numOfChosenNumbers	= 0;			
	var i,y,num;
	var url;
	
	/* Init */
	for( i = 1; i <= maxNumbers; i++ ) AvailNum[ i ] = i; 	
	/*	Draw the numbers	*/	
	for( i = 1; i <= maxRandomNumbers; i++ ){			
		num = Math.ceil( Math.random() * numOfAvailNumbers );	// draw a random number among the available numbers 		
		numOfChosenNumbers++;									// inc number of chosen numbers
		ChosenNum[ numOfChosenNumbers ] = AvailNum[ num ];		// set chosen number
		for( y = num; y <= ( numOfAvailNumbers - 1 ); y++ )	AvailNum[ y ] = AvailNum[ y + 1 ];
		numOfAvailNumbers--;
	}		
	/* Build url and go to page */	
     url = COM_SERVER + '/spill/keno?NT.mc_id=' + tag + '&coupon=activeTab%3D0%26rowPrice%3D5%26drawCount%3D14%26coupon%3DK10-';
     url = url +  (ChosenNum.sort(numberorder)).join("-");
     com_openWindow(url, '_self', '');
}

// *************************************************************************************************
//  Create Lotto coupon given 7 random numbers
//  Antall uker = 5  
function lotto(tag){    
    var maxNumbers = 34;
    var maxRandomNumbers = 7;
	var AvailNum		= new Array();				// holds the available numbers 
	var ChosenNum		= new Array();	            // holds the chosen numbers 
	var numOfAvailNumbers	= 34;
	var numOfChosenNumbers	= 0;			
	var i,y,num;
	var url;
	var streng= '';
	
	for( var u = 1; u <= 10; u++ ){	
  	  numOfAvailNumbers	= 34;
  	  numOfChosenNumbers	= 0;	
  	  ChosenNum		= new Array();	
  	 
  	  /* Init */
  	  for( i = 1; i <= maxNumbers; i++ ) AvailNum[ i ] = i; 	
  	  /*	Draw the numbers	*/	  	 
         for( i = 1; i <= maxRandomNumbers; i++ ){			
         	num = Math.ceil( Math.random() * numOfAvailNumbers );	// draw a random number among the available numbers 		
         	numOfChosenNumbers++;									// inc number of chosen numbers
         	ChosenNum[ numOfChosenNumbers ] = AvailNum[ num ];		// set chosen number
         	for( y = num; y <= ( numOfAvailNumbers - 1 ); y++ )	AvailNum[ y ] = AvailNum[ y + 1 ];
         	numOfAvailNumbers--;       		       		
         }	
         streng = streng + (ChosenNum.sort(numberorder)).join("-") + ',';         
     }  	
     
	/* Build url and go to page */	
     url = COM_SERVER + '/spill/lotto?NT.mc_id=' + tag + '&coupon=multiplier%3D1%26drawCount%3D5%26coupon%3D';
     url = url +  streng;
     com_openWindow(url, '_self', '');
}


//***************************************************
// cookie
function readCookie(nam) {
var tC = document.cookie.split('; ');
for (var i = tC.length - 1; i >= 0; i--) {
var x = tC[i].split('=');
if (nam == x[0]) return unescape(x[1]);}
return null;}
function writeCookie(nam,val) {
document.cookie = nam + '=' + escape(val);}
